﻿using BonjourQuotation.ObjectModel.BusinessData;
using BonjourQuotation.ObjectModel.LoggerData;
using BonjourQuotation.UI.Controllers;
using BonjourQuotation.UI.Models;
using BonjourQuotation.UI.Models.PartialModel;
using BonjourQuotation.UI.Models.Shared;
using BonjourQuotation.UI.ServiceManagers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;



namespace BonjourQuotation.Controllers
{
    public class QuotationController : BaseController
    {
        QuotationManager QuotaManager;
        private readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        [Authorize]
        public ActionResult Quotation(string QuotaId, string Message)
        {     
            QuotationViewModel QuotaVModel = new QuotationViewModel();
            QuotaVModel.Message = Message;
            if (QuotaId == null)
                // QuotaVModel.QuotationID = "5115";
               return QuotationLast();
            else
                QuotaVModel.QuotationID = QuotaId;
            this.SetPermission(QuotaVModel, AllPermVModel);
            var UserName = System.Web.HttpContext.Current.User.Identity.Name;
            var Blocker = this.IsLockedQuota(UserName, Convert.ToInt32(QuotaId));
            if (this.IsLockedQuota(UserName, Convert.ToInt32(QuotaId)) != "")
            {
                this.SetQuotaPermissionsFlase(QuotaVModel);
                QuotaVModel.Message = "Quotation is locked by " + Blocker + ".";
            }
            else
            {
                this.AddQuotaToLockedList(UserName, Convert.ToInt32(QuotaId));
            }
            return View("Quotation", QuotaVModel);  
        }
        [Authorize]
        [HttpPost]
        public JsonResult QuotationLockUnLock(int QuotaId)
        {
            QuotaManager = new QuotationManager();
            var IsDelete = this.LockUnLockQuotaToLockedList(System.Web.HttpContext.Current.User.Identity.Name, QuotaId);
            return this.Json(IsDelete);
        }
        [Authorize]
        public ActionResult QuotationLast()
        {
            QuotaManager = new QuotationManager();
            var QuotaId = QuotaManager.GetQuotationQuotaID(int.MaxValue, UserRegions);
            return Quotation(QuotaId, null);
        }
        [Authorize]
        public ActionResult QuotationFirst()
        {
            QuotaManager = new QuotationManager();
            var QuotaId = QuotaManager.GetQuotationQuotaID(int.MinValue, UserRegions);
            return Quotation(QuotaId, null);
        }
        [Authorize]
        public ActionResult QuotationByRecord(int RecordId)
        {
            QuotaManager = new QuotationManager();
            var QuotaId = QuotaManager.GetQuotationQuotaID(RecordId, UserRegions);
            return Quotation(QuotaId, null);
        }
        [Authorize]
        public ActionResult MakeQuotaToId(string id)
        {
            MessageBoxViewModel MessBoxVModel = new MessageBoxViewModel();
            QuotaManager = new QuotationManager();
            var res = QuotaManager.MakeQuotaToId(id);
            if (res.Message != null)
                MessBoxVModel.Message = res.Message;
            else
                MessBoxVModel.Message = "OK";
            return View("MessageBox", MessBoxVModel);
        }
        [Authorize]
        public PartialViewResult AutoComplete(string PropName, string keyword)
        {
            QuotaManager = new QuotationManager();
            var data = QuotaManager.FindKeywordInEntity(PropName, keyword);
            AutoCompleteViewModel AutoCompVMode = new AutoCompleteViewModel() { Items = data};
            return PartialView("QuotaAutoComplete", AutoCompVMode);
        }
        [Authorize]
        [HttpGet]
        public PartialViewResult LoadVendorContracts(int VendorID, int SeasonID)
        {
            QuotaManager = new QuotationManager();
            var data = QuotaManager.LoadVendorContract(VendorID, SeasonID);
            QuotationVendorContractGridViewModel ContractVMode = new QuotationVendorContractGridViewModel();
            ContractVMode.ContractLuggage = data.Luggage != null ? Convert.ToDecimal(data.Luggage).ToString("F"):"";
            ContractVMode.ContractTax = data.Tax != null ? Convert.ToDecimal(data.Tax).ToString("F"):"";
            ContractVMode.ContractOccTax = data.OccTax != null ? Convert.ToDecimal(data.OccTax).ToString("F"):"";
            ContractVMode.ContractCurr = data.Curr;
            ContractVMode.Rows = new List<QuotationVendorContractGridRowViewModel>();
            if (data.Rows != null)
            {
                foreach (var row in data.Rows)
                {
                    ContractVMode.Rows.Add(new QuotationVendorContractGridRowViewModel
                    {
                        LineNo = row.LineNo.ToString(),
                        Price = row.Price.ToString("F"),
                        ContractDesc = row.Description,
                        ContractCurr = row.Curr,
                        Service = row.Service,
                        ContractStart = row.ContractStart != null ? Convert.ToDateTime(row.ContractStart).ToString("dd/MMM/yy") : "",
                        ContractEnd = row.ContractEnd != null ? Convert.ToDateTime(row.ContractEnd).ToString("dd/MMM/yy") : "",
                    });
                }
            }
            return PartialView("QuotationVendorContractGrid", ContractVMode);

        }
        [Authorize]
        public PartialViewResult LoadQuotaLookupData(string ByRef, string Keyword)
        {
            List<QuotationLookupGridViewModel> QuotaLookUpVModel = new List<QuotationLookupGridViewModel>();
            QuotaManager = new QuotationManager();
            var QuotaLookup = QuotaManager.LoadQuotaLookupData(ByRef, Keyword);
            if (QuotaLookup != null)
            {
                foreach (var lookup in QuotaLookup)
                {
                    QuotaLookUpVModel.Add(new QuotationLookupGridViewModel
                    {
                        ArrivalDate = Convert.ToDateTime(lookup.ArrivalDate).ToString("ddd, dd/MMM/yy"),
                        DepartureDate = Convert.ToDateTime(lookup.DepartureDate).ToString("ddd, dd/MMM/yy"),
                        QuotaCustomer = lookup.QuotaCustomer,
                        QuotaID = lookup.QuotaID.ToString(),
                        QuotaName = lookup.QuotaName,
                    });
                }
            }
            return PartialView("QuotationLookupGrid", QuotaLookUpVModel);
        }
        [Authorize]
        public PartialViewResult LoadQuotationDetails(string QuotaId)
        {
            var QuotaDetVModel = LoadQuotationDetailsDatainit(QuotaId);
            QuotaDetVModel.QuotaIden = QuotaDetVModel.QuotaID;
            this.SetPermission(QuotaDetVModel, AllPermVModel);
            var UserName = System.Web.HttpContext.Current.User.Identity.Name;
            if (this.IsLockedQuota(UserName, Convert.ToInt32(QuotaId)) != "")
            {
                this.SetQuotaPermissionsFlase(QuotaDetVModel);
            }
            return PartialView("QuotationDetails", QuotaDetVModel);
        }
        [Authorize]
        public PartialViewResult LoadQuotationHotels(string QuotaId)   
        {
            var QuotaHotelVModel = LoadQuotationHotelGridDatainit(QuotaId);
            this.SetPermission(QuotaHotelVModel, AllPermVModel);
            var UserName = System.Web.HttpContext.Current.User.Identity.Name;
            if (this.IsLockedQuota(UserName, Convert.ToInt32(QuotaId)) != "")
            {
                this.SetQuotaPermissionsFlase(QuotaHotelVModel);
            }
            return PartialView("QuotationDetailHotelGrid", QuotaHotelVModel);
        }
        [Authorize]
        public PartialViewResult LoadQuotationLunchDinner(string QuotaId)
        {
            var QuotaLunchVModel = LoadQuotationLunchDinnerGridDatainit(QuotaId);
            this.SetPermission(QuotaLunchVModel, AllPermVModel);
            var UserName = System.Web.HttpContext.Current.User.Identity.Name;
            if (this.IsLockedQuota(UserName, Convert.ToInt32(QuotaId)) != "")
            {
                this.SetQuotaPermissionsFlase(QuotaLunchVModel);
            }
            return PartialView("QuotationDetailLunchDinnerGrid", QuotaLunchVModel);
        }
        [Authorize]
        public PartialViewResult LoadQuotationEntrance(string QuotaId)
        {
            var QuotaEntranceVModel = LoadQuotationEntranceGridDatainit(QuotaId);
            this.SetPermission(QuotaEntranceVModel, AllPermVModel);
            var UserName = System.Web.HttpContext.Current.User.Identity.Name;
            if (this.IsLockedQuota(UserName, Convert.ToInt32(QuotaId)) != "")
            {
                this.SetQuotaPermissionsFlase(QuotaEntranceVModel);
            }
            return PartialView("QuotationDetailEntranceGrid", QuotaEntranceVModel);
        }
        [Authorize]
        public PartialViewResult LoadQuotationBus(string QuotaId)
        {
            var QuotaBusVModel = LoadQuotationBusGridDatainit(QuotaId);
            this.SetPermission(QuotaBusVModel, AllPermVModel);
            var UserName = System.Web.HttpContext.Current.User.Identity.Name;
            if (this.IsLockedQuota(UserName, Convert.ToInt32(QuotaId)) != "")
            {
                this.SetQuotaPermissionsFlase(QuotaBusVModel);
            }
            return PartialView("QuotationDetailBusGrid", QuotaBusVModel);
        }
        [Authorize]
        public PartialViewResult LoadQuotationGuide(string QuotaId)
        {
            var QuotaGuideVModel = LoadQuotationGuideGridDatainit(QuotaId);
            this.SetPermission(QuotaGuideVModel, AllPermVModel);
            var UserName = System.Web.HttpContext.Current.User.Identity.Name;
            if (this.IsLockedQuota(UserName, Convert.ToInt32(QuotaId)) != "")
            {
                this.SetQuotaPermissionsFlase(QuotaGuideVModel);
            }
            return PartialView("QuotationDetailGuideGrid", QuotaGuideVModel);
        }
        [Authorize]
        public PartialViewResult LoadQuotationMisc(string QuotaId)
        {
            var QuotaMiscVModel = LoadQuotationMiscGridDatainit(QuotaId);
            this.SetPermission(QuotaMiscVModel, AllPermVModel);
            var UserName = System.Web.HttpContext.Current.User.Identity.Name;
            if (this.IsLockedQuota(UserName, Convert.ToInt32(QuotaId)) != "")
            {
                this.SetQuotaPermissionsFlase(QuotaMiscVModel);
            }
            return PartialView("QuotationDetailMiscGrid", QuotaMiscVModel);
        }
        [Authorize]
        public PartialViewResult LoadQuotationCostPrice(string QuotaId, string FreeCalc)
        {
            ModelState.Clear();
            var QuotaCostVModelList = LoadQuotationCostPriceGridDatainit(QuotaId, FreeCalc);
            this.SetPermission(QuotaCostVModelList, AllPermVModel);
            var UserName = System.Web.HttpContext.Current.User.Identity.Name;
            if (this.IsLockedQuota(UserName, Convert.ToInt32(QuotaId)) != "")
            {
                this.SetQuotaPermissionsFlase(QuotaCostVModelList);
            }
            return PartialView("QuotationDetailCostPriceGrid", QuotaCostVModelList);
        }
        [Authorize]
        public PartialViewResult CalculateQuotaCostPriceGrid(QuotationCostPriceGridViewModel model)
        {
            ModelState.Clear();
            QuotaCostPriceGridBData CostPrData = new QuotaCostPriceGridBData();
            if (model.SSAdjs != null && model.SSAdjs != "")
                CostPrData.SSupAdjs = Convert.ToDecimal(model.SSAdjs);
            if (model.SSAdjsCad != null && model.SSAdjsCad != "")
                CostPrData.SSupAdjsCad = Convert.ToDecimal(model.SSAdjsCad);
            CostPrData.Rows = new List<QuotaCostPriceGridRowBData>();
            if (model.Rows != null)
            {
                foreach (var row in model.Rows)
                    CostPrData.Rows.Add(new QuotaCostPriceGridRowBData
                    {
                        LineNo = Convert.ToInt16(row.LineNo),
                        FAdjst = row.FAdjust != null ? Convert.ToDecimal(row.FAdjust) : (decimal?)null,
                    });
            }
            var QuotaCostVModelList = CalcQuotationCostPriceGridDatainit(model.CostPriceQuotaID, CostPrData, model.CostPriceFreeCalc);
            this.SetPermission(QuotaCostVModelList, AllPermVModel);
            var UserName = System.Web.HttpContext.Current.User.Identity.Name;
            if (this.IsLockedQuota(UserName, Convert.ToInt32(model.CostPriceQuotaID)) != "")
            {
                this.SetQuotaPermissionsFlase(QuotaCostVModelList);
            }
            return PartialView("QuotationDetailCostPriceGrid", QuotaCostVModelList);
        }

        #region Save, New, Update
        [Authorize]
        [HttpPost]
        public PartialViewResult SaveQuotaDetails(QuotationDetailViewModel model)
        {
            ModelState.Clear();
            QuotaManager = new QuotationManager();
            QuotationDetailsBData QuotaBdata = InitQuotaDetailsBData(model);
            var result = QuotaManager.SaveQuotaDetails(QuotaBdata);
            var QuotaDetVModel = LoadQuotationDetailsDatainit(model.QuotaID);
            QuotaDetVModel.QuotaDetailMessage = result.Message;
            QuotaDetVModel.QuotaIden = QuotaDetVModel.QuotaID;
            this.SetPermission(QuotaDetVModel, AllPermVModel);
            return PartialView("QuotationDetails", QuotaDetVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult SaveAsQuotaDetails(string QuotaId)
        {
            ModelState.Clear();
            QuotaManager = new QuotationManager();
            var result = QuotaManager.SaveAsQuotationBDataByQuotaId(QuotaId, User.Identity.Name);
            if(result != null && result.Error.Message == null)
            {
                string content = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ProposalPath"]) + "//" + QuotaId + "//" + result.Proposal;
                if (System.IO.File.Exists(content))
                {
                    string folder = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ProposalPath"]) + "//" + result.QuotaID;
                    if (System.IO.Directory.Exists(folder))
                        System.IO.File.Copy(content, Path.Combine(folder, Path.GetFileName(content)), true);
                    else
                    {
                        Directory.CreateDirectory(folder);
                        System.IO.File.Copy(content, Path.Combine(folder, Path.GetFileName(content)), true);
                    }
                }       
            }
            var QuotaDetVModel = LoadQuotationDetailsSaveAsDatainit(result);
            QuotaDetVModel.QuotaIden = QuotaDetVModel.QuotaID;
            QuotaDetVModel.QuotaDetailMessage = result.Error.Message == null ? "Quota copied successfully." : "Error during Quota copy.";
            this.SetPermission(QuotaDetVModel, AllPermVModel);
            return PartialView("QuotationDetails", QuotaDetVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult NewQuotationDetails()
        {
            var QuotaDetVModel = NewQuotationDetailsDatainit();
            this.SetPermission(QuotaDetVModel, AllPermVModel);
            return PartialView("QuotationDetails", QuotaDetVModel);
        }

        #region Tabs Line
        [Authorize]
        public PartialViewResult NewLineQuotationHotels(string QuotaId)
        {
            QuotaManager = new QuotationManager();
            var QuotaHotelBdata = QuotaManager.NewLineQuotaHotelGrid(QuotaId);
            var QuotaHotelVModel = QuotationHotelGridDatainit(QuotaHotelBdata);
            this.SetPermission(QuotaHotelVModel, AllPermVModel);
            return PartialView("QuotationDetailHotelGrid", QuotaHotelVModel);
        }
        [Authorize]
        public PartialViewResult InsertLineQuotationHotels(string QuotaId, string LineNum)
        {
            QuotaManager = new QuotationManager();
            var QuotaHotelBdata = QuotaManager.InsertLineQuotaHotelGrid(QuotaId, LineNum);
            var QuotaHotelVModel = QuotationHotelGridDatainit(QuotaHotelBdata);
            this.SetPermission(QuotaHotelVModel, AllPermVModel);
            return PartialView("QuotationDetailHotelGrid", QuotaHotelVModel);
        }
        [Authorize]
        public PartialViewResult UpdateQuotationHotels(QuotationHotelGridViewModel model)
        {
            ModelState.Clear();
            var QuotaHotelBData = InitQuotaHotelGridBData(model);
            QuotaManager = new QuotationManager();
            var QuotaHtlShowBdata = QuotaManager.UpdateQuotaHotelGrid(QuotaHotelBData, model.QuotaHotelIsNewLine, model.QuotaHotelIsInsert, model.QuotaHotelInsertRow);
            var QuotaHotelVModel = QuotationHotelGridDatainit(QuotaHtlShowBdata);
            this.SetPermission(QuotaHotelVModel, AllPermVModel);
            QuotaHotelVModel.QuotaHotelErrorCode = QuotaHtlShowBdata.Error.errorCode != null ? QuotaHtlShowBdata.Error.errorCode.ToString() : "";
            QuotaHotelVModel.QuotaHotelErrorMessage = QuotaHtlShowBdata.Error.Message;
            return PartialView("QuotationDetailHotelGrid", QuotaHotelVModel);
        }
        [Authorize]
        public PartialViewResult NewLineQuotationLunchDinner(string QuotaId)
        {
            QuotaManager = new QuotationManager();
            var QuotaLunchBdata = QuotaManager.NewLineQuotaLunchDinnerGrid(QuotaId);
            var QuotaLunchVModel = QuotationLunchDinnerGridDatainit(QuotaLunchBdata);
            this.SetPermission(QuotaLunchVModel, AllPermVModel);
            return PartialView("QuotationDetailLunchDinnerGrid", QuotaLunchVModel);
        }
        [Authorize]
        public PartialViewResult UpdateQuotationLunchDinner(QuotationLunchDinnerGridViewModel model)
        {
            var QuotaLunchBData = InitQuotaLunchDinnerGridBData(model);
            QuotaManager = new QuotationManager();
            var QuotaLunchShowBdata = QuotaManager.UpdateQuotaLunchDinnerGrid(QuotaLunchBData);
            var QuotaLunchVModel = QuotationLunchDinnerGridDatainit(QuotaLunchShowBdata);
            ModelState.Clear();
            this.SetPermission(QuotaLunchVModel, AllPermVModel);
            QuotaLunchVModel.QuotaLunchDinnerErrorCode = QuotaLunchShowBdata.Error.errorCode != null ? QuotaLunchShowBdata.Error.errorCode.ToString() : "";
            QuotaLunchVModel.QuotaLunchDinnerErrorMessage = QuotaLunchShowBdata.Error.Message;
            return PartialView("QuotationDetailLunchDinnerGrid", QuotaLunchVModel);
        }
        [Authorize]
        public PartialViewResult InsertLineQuotationLunchDinner(string QuotaId, string LineNum)
        {
            QuotaManager = new QuotationManager();
            var QuotaLunchBdata = QuotaManager.InsertLineQuotaLunchDinnerGrid(QuotaId, LineNum);
            var QuotaLunchVModel = QuotationLunchDinnerGridDatainit(QuotaLunchBdata);
            this.SetPermission(QuotaLunchVModel, AllPermVModel);
            return PartialView("QuotationDetailLunchDinnerGrid", QuotaLunchVModel);
        }
        [Authorize]
        public PartialViewResult NewLineQuotationEntrance(string QuotaId)
        {
            QuotaManager = new QuotationManager();
            var QuotaEntranceBdata = QuotaManager.NewLineQuotaEntranceGrid(QuotaId);
            var QuotaEntranceVModel = QuotationEntranceGridDatainit(QuotaEntranceBdata);
            this.SetPermission(QuotaEntranceVModel, AllPermVModel);
            return PartialView("QuotationDetailEntranceGrid", QuotaEntranceVModel);
        }
        [Authorize]
        public PartialViewResult UpdateQuotationEntrance(QuotationEntranceGridViewModel model)
        {
            var QuotaEntranceBData = InitQuotaEntranceGridBData(model);
            QuotaManager = new QuotationManager();
            var QuotaEntranceShowBdata = QuotaManager.UpdateQuotaEntranceGrid(QuotaEntranceBData);
            var QuotaEntranceVModel = QuotationEntranceGridDatainit(QuotaEntranceShowBdata);
            ModelState.Clear();
            this.SetPermission(QuotaEntranceVModel, AllPermVModel);
            QuotaEntranceVModel.QuotaEntranceErrorCode = QuotaEntranceShowBdata.Error.errorCode != null ? QuotaEntranceShowBdata.Error.errorCode.ToString() : "";
            QuotaEntranceVModel.QuotaEntranceErrorMessage = QuotaEntranceShowBdata.Error.Message;
            return PartialView("QuotationDetailEntranceGrid", QuotaEntranceVModel);
        }
        [Authorize]
        public PartialViewResult InsertLineQuotationEntrance(string QuotaId, string LineNum)
        {
            QuotaManager = new QuotationManager();
            var QuotaEntranceBdata = QuotaManager.InsertLineQuotaEntranceGrid(QuotaId, LineNum);
            var QuotaEntranceVModel = QuotationEntranceGridDatainit(QuotaEntranceBdata);
            this.SetPermission(QuotaEntranceVModel, AllPermVModel);
            return PartialView("QuotationDetailEntranceGrid", QuotaEntranceVModel);
        }
        [Authorize]
        public PartialViewResult NewLineQuotationMisc(string QuotaId)
        {
            QuotaManager = new QuotationManager();
            var QuotaMiscBdata = QuotaManager.NewLineQuotaMiscGrid(QuotaId);
            var QuotaMiscVModel = QuotationMiscGridDatainit(QuotaMiscBdata);
            this.SetPermission(QuotaMiscVModel, AllPermVModel);
            return PartialView("QuotationDetailMiscGrid", QuotaMiscVModel);
        }
        [Authorize]
        public PartialViewResult UpdateQuotationMisc(QuotationMiscGridViewModel model)
        {
            var QuotaMiscBData = InitQuotaMiscGridBData(model);
            QuotaManager = new QuotationManager();
            var QuotaMiscShowBdata = QuotaManager.UpdateQuotaMiscGrid(QuotaMiscBData);
            var QuotaMiscVModel = QuotationMiscGridDatainit(QuotaMiscShowBdata);
            this.SetPermission(QuotaMiscVModel, AllPermVModel);
            return PartialView("QuotationDetailMiscGrid", QuotaMiscVModel);
        }
        [Authorize]
        public PartialViewResult InsertLineQuotationMisc(string QuotaId, string LineNum)
        {
            QuotaManager = new QuotationManager();
            var QuotaMiscBdata = QuotaManager.InsertLineQuotaMiscGrid(QuotaId, LineNum);
            var QuotaMiscVModel = QuotationMiscGridDatainit(QuotaMiscBdata);
            this.SetPermission(QuotaMiscVModel, AllPermVModel);
            return PartialView("QuotationDetailMiscGrid", QuotaMiscVModel);
        }
        [Authorize]
        public PartialViewResult NewLineQuotationBus(string QuotaId)
        {
            QuotaManager = new QuotationManager();
            var QuotaBusBdata = QuotaManager.NewLineQuotaBusGrid(QuotaId);
            var QuotaBusVModel = QuotationBusGridDatainit(QuotaBusBdata, true);
            this.SetPermission(QuotaBusVModel, AllPermVModel);
            return PartialView("QuotationDetailBusGrid", QuotaBusVModel);
        }
        [Authorize]
        public PartialViewResult UpdateQuotationBus(QuotationBusGridViewModel model)
        {
            var QuotaBusBData = InitQuotaBusGridBData(model);
            QuotaManager = new QuotationManager();
            var QuotaBusShowBdata = QuotaManager.UpdateQuotaBusGrid(QuotaBusBData);
            var QuotaBusVModel = QuotationBusGridDatainit(QuotaBusShowBdata, false);
            ModelState.Clear();
            this.SetPermission(QuotaBusVModel, AllPermVModel);
            QuotaBusVModel.QuotaBusErrorCode = QuotaBusShowBdata.Error.errorCode != null ? QuotaBusShowBdata.Error.errorCode.ToString() : "";
            QuotaBusVModel.QuotaBusErrorMessage = QuotaBusShowBdata.Error.Message;
            return PartialView("QuotationDetailBusGrid", QuotaBusVModel);
        }
        [Authorize]
        public PartialViewResult InsertLineQuotationBus(string QuotaId, string LineNum)
        {
            QuotaManager = new QuotationManager();
            var QuotaBusBdata = QuotaManager.InsertLineQuotaBusGrid(QuotaId, LineNum);
            var QuotaBusVModel = QuotationBusGridDatainit(QuotaBusBdata, true);
            this.SetPermission(QuotaBusVModel, AllPermVModel);
            return PartialView("QuotationDetailBusGrid", QuotaBusVModel);
        }
        [Authorize]
        public PartialViewResult NewLineQuotationGuide(string QuotaId)
        {
            QuotaManager = new QuotationManager();
            var QuotaGuideBdata = QuotaManager.NewLineQuotaGuideGrid(QuotaId);
            var QuotaGuideVModel = QuotationGuideGridDatainit(QuotaGuideBdata, true);
            this.SetPermission(QuotaGuideVModel, AllPermVModel);
            return PartialView("QuotationDetailGuideGrid", QuotaGuideVModel);
        }
        [Authorize]
        public PartialViewResult UpdateQuotationGuide(QuotationGuideGridViewModel model)
        {
            var QuotaGuideBData = InitQuotaGuideGridBData(model);
            QuotaManager = new QuotationManager();
            var QuotaGuideShowBdata = QuotaManager.UpdateQuotaGuideGrid(QuotaGuideBData);
            var QuotaGuideVModel = QuotationGuideGridDatainit(QuotaGuideShowBdata, false);
            ModelState.Clear();
            this.SetPermission(QuotaGuideVModel, AllPermVModel);
            return PartialView("QuotationDetailGuideGrid", QuotaGuideVModel);
        }
        [Authorize]
        public PartialViewResult InsertLineQuotationGuide(string QuotaId, string LineNum)
        {
            QuotaManager = new QuotationManager();
            var QuotaGuideBdata = QuotaManager.InsertLineQuotaGuideGrid(QuotaId, LineNum);
            var QuotaGuideVModel = QuotationGuideGridDatainit(QuotaGuideBdata, true);
            this.SetPermission(QuotaGuideVModel, AllPermVModel);
            return PartialView("QuotationDetailGuideGrid", QuotaGuideVModel);
        }

        #endregion

        #endregion

        #region Delete
        [Authorize]
        public PartialViewResult RemoveQuotationHotels(int ItmID, string QuotaId, string LineNo)
        {
            QuotaManager = new QuotationManager();
            var error = QuotaManager.RemoveFromGrid(ItmID, QuotaId, LineNo, "Hotel");
            //if(error.Message == null)
            var QuotaHotelVModel = LoadQuotationHotelGridDatainit(QuotaId);
            this.SetPermission(QuotaHotelVModel, AllPermVModel);
            return PartialView("QuotationDetailHotelGrid", QuotaHotelVModel);
        }
        [Authorize]
        public PartialViewResult RemoveQuotationLunchDinner(int ItmID, string QuotaId, string LineNo)
        {
            QuotaManager = new QuotationManager();
            var error = QuotaManager.RemoveFromGrid(ItmID, QuotaId, LineNo, "Lunch");
            //if(error.Message == null)
            var QuotaLunchVModel = LoadQuotationLunchDinnerGridDatainit(QuotaId);
            this.SetPermission(QuotaLunchVModel, AllPermVModel);
            return PartialView("QuotationDetailLunchDinnerGrid", QuotaLunchVModel);
        }
        [Authorize]
        public PartialViewResult RemoveQuotationEntrance(int ItmID, string QuotaId, string LineNo)
        {
            ModelState.Clear();
            QuotaManager = new QuotationManager();
            var error = QuotaManager.RemoveFromGrid(ItmID, QuotaId, LineNo, "Entrance");
            //if(error.Message == null)
            var QuotaEntranceVModel = LoadQuotationEntranceGridDatainit(QuotaId);
            this.SetPermission(QuotaEntranceVModel, AllPermVModel);
            return PartialView("QuotationDetailEntranceGrid", QuotaEntranceVModel);
        }
        [Authorize]
        public PartialViewResult RemoveQuotationMisc(int ItmID, string QuotaId, string LineNo)
        {
            QuotaManager = new QuotationManager();
            var error = QuotaManager.RemoveFromGrid(ItmID, QuotaId, LineNo, "Misc");
            //if(error.Message == null)
            var QuotaMiscVModel = LoadQuotationMiscGridDatainit(QuotaId);
            this.SetPermission(QuotaMiscVModel, AllPermVModel);
            return PartialView("QuotationDetailMiscGrid", QuotaMiscVModel);
        }
        [Authorize]
        public PartialViewResult RemoveQuotationBus(int ItmID, string QuotaId, string LineNo)
        {
            QuotaManager = new QuotationManager();
            var error = QuotaManager.RemoveFromGrid(ItmID, QuotaId, LineNo, "Bus");
            //if(error.Message == null)
            var QuotaBusVModel = LoadQuotationBusGridDatainit(QuotaId);
            this.SetPermission(QuotaBusVModel, AllPermVModel);
            return PartialView("QuotationDetailBusGrid", QuotaBusVModel);
        }
        [Authorize]
        public PartialViewResult RemoveQuotationGuide(int ItmID, string QuotaId, string LineNo)
        {
            QuotaManager = new QuotationManager();
            var error = QuotaManager.RemoveFromGrid(ItmID, QuotaId, LineNo, "Guide");
            //if(error.Message == null)
            var QuotaGuideVModel = LoadQuotationGuideGridDatainit(QuotaId);
            this.SetPermission(QuotaGuideVModel, AllPermVModel);
            return PartialView("QuotationDetailGuideGrid", QuotaGuideVModel);
        }
        [Authorize]
        public PartialViewResult RemoveQuotationCostPrice(int ItmID, string QuotaId, string LineNo, string FreeCalc)
        {
            QuotaManager = new QuotationManager();
            var error = QuotaManager.RemoveFromGrid(ItmID, QuotaId, LineNo, "Price");
            //if(error.Message == null)
            var QuotaPriceVModel = LoadQuotationCostPriceGridDatainit(QuotaId, FreeCalc);
            this.SetPermission(QuotaPriceVModel, AllPermVModel);
            return PartialView("QuotationDetailCostPriceGrid", QuotaPriceVModel);
        }

        #endregion

        #region proposal
        [Authorize]
        public FileResult ViewProposal(string QuotaID, string DocumentName)
        {
            string content = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ProposalPath"]) + "//" + QuotaID + "//" + DocumentName;
            if (System.IO.File.Exists(content))
                return File(content, System.Net.Mime.MediaTypeNames.Application.Octet, Path.GetFileName(content));
            else
                return null;

        }
        [Authorize]
        public ActionResult UploadProposal(string QuotaIden)
        {
            if (System.Web.HttpContext.Current.Request.Files.Count > 0)
            {
                HttpPostedFile file = System.Web.HttpContext.Current.Request.Files[0];
                if (file.ContentLength > 2048 * 1024)
                {
                    return Quotation(QuotaIden, "Upload File can not be larger than 2MB.");
                }
                //  string ContentFolder = @"/Proposal" + "\\" + QuotaIden;
                string ContentFolder = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ProposalPath"]) + "//" + QuotaIden;
                if (Directory.Exists(ContentFolder))
                {
                    foreach (string filePath in Directory.GetFiles(ContentFolder))
                    {
                        //if (filePath.Contains(".doc"))
                        System.IO.File.Delete(filePath);
                    }
                }
                else
                    Directory.CreateDirectory(ContentFolder);
                file.SaveAs(ContentFolder + "//" + file.FileName);
                QuotaManager = new QuotationManager();
                var error = QuotaManager.UploadProposal(QuotaIden, file.FileName);
                if (error.errorCode == 0)
                    return Quotation(QuotaIden, null);
                else
                    return Quotation(QuotaIden, "Error uploading proposal.");
            }
            return Quotation(QuotaIden, "Error uploading proposal.");
        }
        #endregion


        #region Advanced Search

        [Authorize]
        [HttpGet]
        public PartialViewResult QuotationAdvancedSearch()
        {
            var QuotaAdVModel = new QuotationAdvancedSearchViewModel();
            QuotaManager = new QuotationManager();
            var QuotaAsBData = QuotaManager.QuotationAdvancedSearchBData();
            QuotaAdVModel.QuotaCountryAd = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaAdVModel.RegionAd = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaAdVModel.SeasonAd = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaAdVModel.ArrivalCityAd = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaAdVModel.EmployeeIdAd = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaAdVModel.CustomerIdAd = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaAdVModel.DepartureCityAd = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaAdVModel.AcceptedAd = new List<System.Web.WebPages.Html.SelectListItem>()
            {
                new System.Web.WebPages.Html.SelectListItem(){Text="Yes", Value = "0"},
                new System.Web.WebPages.Html.SelectListItem(){Text="No", Value = "1"},
            };
            // 3 types of free calc
            QuotaAdVModel.FreeCalcTypeAd = new List<System.Web.WebPages.Html.SelectListItem>()
            {
                new System.Web.WebPages.Html.SelectListItem(){Text="No Free", Value = "0"},
                new System.Web.WebPages.Html.SelectListItem(){Text="1 Pax in Dbl Free", Value = "1"},
                new System.Web.WebPages.Html.SelectListItem(){Text="Single Free", Value = "2"},
            };
            
            // data inits
            // type
            if (QuotaAsBData.QuotaCountry != null)
            {
                foreach (var ctr in QuotaAsBData.QuotaCountry)
                    QuotaAdVModel.QuotaCountryAd.Add(new System.Web.WebPages.Html.SelectListItem() { Text = ctr.Value, Value = ctr.Key.ToString() });
            }
                // region
            if (QuotaAsBData.Region != null)
            {
                foreach (var region in QuotaAsBData.Region)
                    QuotaAdVModel.RegionAd.Add(new System.Web.WebPages.Html.SelectListItem() { Text = region.Value, Value = region.Value });
            }
                // customer
           // QuotaAdVModel.CustomerId.Add(new System.Web.WebPages.Html.SelectListItem() { Text = "", Value = "0" });
            if (QuotaAsBData.CustomerId != null)
            {
                foreach (var cust in QuotaAsBData.CustomerId)
                    QuotaAdVModel.CustomerIdAd.Add(new System.Web.WebPages.Html.SelectListItem() { Text = cust.Value, Value = cust.Key.ToString() });
            }
            // Season
            if (QuotaAsBData.Season != null)
            {
                foreach (var season in QuotaAsBData.Season)
                    QuotaAdVModel.SeasonAd.Add(new System.Web.WebPages.Html.SelectListItem() { Text = season.Value, Value = season.Key.ToString() });
            }
            // Employee
            if (QuotaAsBData.Employee != null)
            {
                foreach (var empl in QuotaAsBData.Employee)
                    QuotaAdVModel.EmployeeIdAd.Add(new System.Web.WebPages.Html.SelectListItem() { Text = empl.Value, Value = empl.Key.ToString() });
            }
            // arrival city
            if (QuotaAsBData.ArrivalCity != null)
            {
                foreach (var arrcity in QuotaAsBData.ArrivalCity)
                    QuotaAdVModel.ArrivalCityAd.Add(new System.Web.WebPages.Html.SelectListItem() { Text = arrcity.Value, Value = arrcity.Value });
            }
            // departure city
            if (QuotaAsBData.DepartureCity != null)
            {
                foreach (var depcity in QuotaAsBData.DepartureCity)
                    QuotaAdVModel.DepartureCityAd.Add(new System.Web.WebPages.Html.SelectListItem() { Text = depcity.Value, Value = depcity.Value });
            }

            return PartialView("QuotationAdvancedSearch", QuotaAdVModel);
        }

        [Authorize]
        [HttpPost]
        public PartialViewResult QuotationAdvancedSearch(QuotationAdvancedSearchViewModel model)
        {
            QuotationAdvancedSearchBData AdSBdata = new QuotationAdvancedSearchBData()
            {
                Accepted = model.SelectedAcceptedAd != null ? model.SelectedAcceptedAd=="0"?true:false : (bool?)null,
                ArrivalDateFrom = model.ArrivalDateFromAd != null? Convert.ToDateTime(model.ArrivalDateFromAd): (DateTime?)null,
                ArrivalDateTo = model.ArrivalDateToAd != null ? Convert.ToDateTime(model.ArrivalDateToAd) : (DateTime?)null,
                NoNights = model.NoNightsAd != null ?Convert.ToByte(model.NoNightsAd): (byte?)null,
                profit = model.profitAd != null?Convert.ToDouble(model.profitAd):(double?)null,
                QuotaCode = model.QuotaCodeAd,
                QuotaDateFrom = model.QuotaDateFromAd != null ? Convert.ToDateTime(model.QuotaDateFromAd) : (DateTime?)null,
                QuotaDateTo = model.QuotaDateToAd != null ? Convert.ToDateTime(model.QuotaDateToAd) : (DateTime?)null,
                LastUpdateFrom = model.LastUpdateFromAd != null ? Convert.ToDateTime(model.LastUpdateFromAd) : (DateTime?)null,
                LastUpdateTo = model.LastUpdateToAd != null ? Convert.ToDateTime(model.LastUpdateToAd) : (DateTime?)null,
                QuotaName = model.QuotaNameAd,
                SelectedArrivalCity = model.SelectedArrivalCityAd,
                SelectedCustomerId = model.SelectedCustomerIdAd != null ? Convert.ToInt32(model.SelectedCustomerIdAd):(int?)null,
                SelectedDepartureCity = model.SelectedDepartureCityAd,
                SelectedEmployeeId = model.SelectedEmployeeIdAd != null ? Convert.ToInt32(model.SelectedEmployeeIdAd) : (int?)null,
                SelectedFreeCalcType = model.SelectedFreeCalcTypeAd != null? Convert.ToInt16(model.SelectedFreeCalcTypeAd) : (short?)null,
                SelectedQuotaType = model.SelectedQuotaTypeAd != null? Convert.ToInt16(model.SelectedQuotaTypeAd): (short?)null,
                SelectedRegion = model.SelectedRegionAd,
                SelectedSeason = model.SelectedSeasonAd != null ?Convert.ToInt32(model.SelectedSeasonAd):(int?)null,

            };
            QuotaManager = new QuotationManager();
            var QuotaAdSearchBData = QuotaManager.QuotationAdvancedSearch(AdSBdata);
            var AdvancedSearchGridVM = new List<QuotationAdvancedSearchGridViewModel>();
            if (QuotaAdSearchBData != null)
            {
                foreach (var AdSdata in QuotaAdSearchBData)
                {
                    AdvancedSearchGridVM.Add(new QuotationAdvancedSearchGridViewModel
                    {
                        ArrivalDate = AdSdata.ArrivalDate != null ? Convert.ToDateTime(AdSdata.ArrivalDate).ToString("ddd, dd/MMM/yy") : "",
                        LastUpdateDate = AdSdata.LastUpdateDate != null ? Convert.ToDateTime(AdSdata.LastUpdateDate).ToString("ddd, dd/MMM/yy") : "",
                        QuotaCode = AdSdata.QuotaCode,
                        QuotaID = AdSdata.QuotaID.ToString(),
                        Customer = AdSdata.Customer,
                        QuotaName = AdSdata.QuotaName,
                    });
                }
            }
            return PartialView("QuotationAdvancedSearchGrid", AdvancedSearchGridVM);
        }

        #endregion

        #region Create Group
        [Authorize]
        [HttpPost]
        public JsonResult QuotationCreateGroup()
        {
            QuotaManager = new QuotationManager();
            var GroupId = QuotaManager.CreateNonGirGroup();
            return this.Json(GroupId);
        }
        [Authorize]
        [HttpPost]
        public JsonResult QuotationSaveGroup(QuotationGroupDetailViewModel model)
        {
            QuotaManager = new QuotationManager();
            var GroupBData = InitQuotaSaveGroupBData(model);            
            var Error = QuotaManager.SaveNonGirGroup(GroupBData);
            return this.Json(Error);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult QuotationCreateGirGroup(int QuotaID)
        {
            QuotaManager = new QuotationManager();
            var GirData = QuotaManager.CreateGirNonGirGroup(QuotaID, true, User.Identity.Name);
            var GirGroupVModel = InitQuotaCreateGirGroupViewModel(GirData, true, null);
            this.SetPermission(GirGroupVModel, AllPermVModel);
            var UserName = System.Web.HttpContext.Current.User.Identity.Name;
            if (this.IsLockedQuota(UserName, Convert.ToInt32(QuotaID)) != "")
            {
                this.SetQuotaPermissionsFlase(GirGroupVModel);
            }
            return PartialView("QuotationGirGroupGrid", GirGroupVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult QuotationCreateGroupSeries(int QuotaID, string CustomerID)
        {
            QuotaManager = new QuotationManager();
            var GirData = QuotaManager.CreateGirNonGirGroup(QuotaID, false, User.Identity.Name);
            var GirGroupVModel = InitQuotaCreateGirGroupViewModel(GirData, false, null);
            GirGroupVModel.AddGirSelCustomerID = CustomerID;
            this.SetPermission(GirGroupVModel, AllPermVModel);
            var UserName = System.Web.HttpContext.Current.User.Identity.Name;
            if (this.IsLockedQuota(UserName, Convert.ToInt32(QuotaID)) != "")
            {
                this.SetQuotaPermissionsFlase(GirGroupVModel);
            }
            return PartialView("QuotationGirGroupGrid", GirGroupVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult QuotationPushGroup(int GroupID, bool Gir)
        {
            QuotaManager = new QuotationManager();
            var Data = QuotaManager.NewGirNonGirGroupPush(GroupID, Gir, User.Identity.Name);
            var GroupVModel = InitQuotaCreateGirGroupViewModel(Data, Gir, null);
            this.SetPermission(GroupVModel, AllPermVModel);
            return PartialView("QuotationGirGroupGrid", GroupVModel);
        }
        [Authorize]
        [HttpPost]
        public PartialViewResult QuotationSaveGirGroup(QuotationGirGroupGridViewModel model)
        {
            ModelState.Clear();
            QuotaManager = new QuotationManager();
            if (model.IsNewGroup)
            {
                QuotationGirGroupGridBData GirGrBData = new QuotationGirGroupGridBData()
                {
                    SelStatusID = model.AddGirSelStatus != null ? Convert.ToInt32(model.AddGirSelStatus): (int?)null,
                    SelCountryID = model.AddGirSelCountryID != null ? Convert.ToInt32(model.AddGirSelCountryID) : 0,
                    QuotaID = model.AddGirQuotaID,
                    AsGir = model.AddGirAsGir,
                    GroupCode = model.AddGirGroupCode,
                    GroupID = model.AddGirGroupID,
                    GroupName = model.AddGirGroupName,
                    SelCustomerID = model.AddGirMainCustomerID != null ? Convert.ToInt32(model.AddGirMainCustomerID) : 0,
                    SeasonID = model.AddGirSeasonID != null ? Convert.ToInt32(model.AddGirSeasonID) : 0,
                    ArrivalDate = model.AddGirArrivalDate != null ? Convert.ToDateTime(model.AddGirArrivalDate) : (DateTime?)null,
                    NoNights = model.AddGirNoNights != null ? Convert.ToInt16(model.AddGirNoNights) : (short?)null,
                    DepartureDate = model.AddGirNoNights != null && model.AddGirArrivalDate != null ? Convert.ToDateTime(model.AddGirArrivalDate).AddDays(Convert.ToInt16(model.AddGirNoNights)) : (DateTime?)null,
                    Pax = model.AddGirPax != null ? Convert.ToInt16(model.AddGirPax):(short?)null,
                    Room = model.AddGirRoom != null ? Convert.ToInt16(model.AddGirRoom) : (short?)null,
                    SelHotelEmpID = model.AddGirSelHotelEmpID != null ? Convert.ToInt32(model.AddGirSelHotelEmpID) : 0,
                    SelAttrEmpID = model.AddGirSelAttrEmpID != null ? Convert.ToInt32(model.AddGirSelAttrEmpID) : 0,
                    SelMiscEmpID = model.AddGirSelMiscEmpID != null ? Convert.ToInt32(model.AddGirSelMiscEmpID) : 0,
                    SelBusEmpID = model.AddGirSelBusEmpID != null ? Convert.ToInt32(model.AddGirSelBusEmpID) : 0,
                };
                if (!model.IsGir)
                    GirGrBData.SelCustomerID = Convert.ToInt32(model.AddGirSelCustomerID);
                var GirData = QuotaManager.NewGirNonGirGroup(GirGrBData, model.IsGir, User.Identity.Name);
                var GirGroupVModel = InitQuotaCreateGirGroupViewModel(GirData, model.IsGir, model.AddGirSelCustomerID);
                if (GirData.Error != null)
                    GirGroupVModel.GrActionMessage = GirData.Error.Message == null ? "New group successfully created" : GirData.Error.Message;
                this.SetPermission(GirGroupVModel, AllPermVModel);
                return PartialView("QuotationGirGroupGrid", GirGroupVModel);
            }
            if (model.IsNewInv)
            {
                QuotationGirGroupGridBData GirGrBData = new QuotationGirGroupGridBData()
                {
                    InvCustomerID = model.AddInvCustomerID != null ? Convert.ToInt32(model.AddInvCustomerID) : 0,
                    InvGroupID = model.AddInvSelGroupID != null ? Convert.ToInt32(model.AddInvSelGroupID) : 0,
                    QuotaID = model.AddGirQuotaID,
                    InvPricePerPerson = model.AddInvPricePerPerson != null ? Convert.ToDecimal(model.AddInvPricePerPerson) : 0,
                    InvPriceFBoard = model.AddInvPriceFBoard != null ? Convert.ToDecimal(model.AddInvPriceFBoard) : 0,
                    InvPriceSingleSup = model.AddInvPriceSingleSup != null ? Convert.ToDecimal(model.AddInvPriceSingleSup) : 0,
                    InvPricePerPersonCad = model.AddInvPricePerPersonCad != null ? Convert.ToDecimal(model.AddInvPricePerPersonCad) : 0,
                    InvPriceFBoardCad = model.AddInvPriceFBoardCad != null ? Convert.ToDecimal(model.AddInvPriceFBoardCad) : 0,
                    InvPriceSingleSupCad = model.AddInvPriceSingleSupCad != null ? Convert.ToDecimal(model.AddInvPriceSingleSupCad) : 0,
                };

                var GirData = QuotaManager.NewGirGroupCustomer(GirGrBData, User.Identity.Name);
                var GirGroupVModel = InitQuotaCreateGirGroupViewModel(GirData, model.IsGir, model.AddGirSelCustomerID);
                if (GirData.Error != null)
                    GirGroupVModel.GrActionMessage = GirData.Error.Message == null ? "New customer successfully added" : GirData.Error.Message;
                this.SetPermission(GirGroupVModel, AllPermVModel);
                return PartialView("QuotationGirGroupGrid", GirGroupVModel);
            }
            if (model.IsSaveGroup)
            {
                QuotationGirGroupGridBData GirGrBData = new QuotationGirGroupGridBData();
                GirGrBData.Rows = new List<QuotationGirGroupGridRowBData>();
                GirGrBData.QuotaID = model.AddGirQuotaID;
                if (model.Rows != null)
                {
                    foreach (var row in model.Rows)
                        GirGrBData.Rows.Add(new QuotationGirGroupGridRowBData()
                        {
                            SelStatusID = row.GirSelStatusID != null ? Convert.ToInt32(row.GirSelStatusID) : (int?)null,
                            SelCountryID = row.GirSelCountryID != null ? Convert.ToInt32(row.GirSelCountryID) : 0,
                            GroupCode = row.GirGroupCode,
                            GroupID = row.GirGroupID,
                            GroupName = row.GirGroupName,
                            // SelCustomerID = 0,
                            // SeasonID = row.GirSeasonID != null ? Convert.ToInt32(model.AddGirSeasonID) : 0,
                            ArrivalDate = row.GirArrivalDate != null ? Convert.ToDateTime(row.GirArrivalDate) : (DateTime?)null,
                            DepartureDate = row.GirNoNights != null && row.GirArrivalDate != null ? Convert.ToDateTime(row.GirArrivalDate).AddDays(Convert.ToInt16(row.GirNoNights)) : (DateTime?)null,
                            Pax = row.GirPax != null ? Convert.ToInt16(row.GirPax) : (short?)null,
                            Room = row.GirRoom != null ? Convert.ToInt16(row.GirRoom) : (short?)null,
                        });
                }
                var GirData = QuotaManager.SaveGirNonGirGroup(GirGrBData, model.IsGir, User.Identity.Name);
                var GirGroupVModel = InitQuotaCreateGirGroupViewModel(GirData, model.IsGir, model.AddGirSelCustomerID);
                GirGroupVModel.AddGirNoNights = model.AddGirNoNights;
                if (GirData.Error != null)
                    GirGroupVModel.GrActionMessage = GirData.Error.Message == null ? "Successfully saved" : GirData.Error.Message;
                this.SetPermission(GirGroupVModel, AllPermVModel);
                return PartialView("QuotationGirGroupGrid", GirGroupVModel);
            }
            if (model.IsSaveInvoice)
            {
                QuotationGirGroupGridBData GirGrBData = new QuotationGirGroupGridBData();
                GirGrBData.InvRows = new List<QuotationGirInvoiceGridRowBData>();
                GirGrBData.QuotaID = model.AddGirQuotaID;
                if (model.InvRows != null)
                {
                    foreach (var invrow in model.InvRows)
                        GirGrBData.InvRows.Add(new QuotationGirInvoiceGridRowBData()
                        {
                            InvCustomerID = invrow.InvCustomerID != null ? Convert.ToInt32(invrow.InvCustomerID) : 0,
                            InvGroupID = invrow.InvGroupID,
                            InvPricePerPerson = invrow.InvPricePerPerson != null ? Convert.ToDecimal(invrow.InvPricePerPerson) : 0,
                            InvPriceFBoard = invrow.InvPriceFBoard != null ? Convert.ToDecimal(invrow.InvPriceFBoard) : 0,
                            InvPriceSingleSup = invrow.InvPriceSingleSup != null ? Convert.ToDecimal(invrow.InvPriceSingleSup) : 0,
                            InvPricePerPersonCad = invrow.InvPricePerPersonCad != null ? Convert.ToDecimal(invrow.InvPricePerPersonCad) : 0,
                            InvPriceFBoardCad = invrow.InvPriceFBoardCad != null ? Convert.ToDecimal(invrow.InvPriceFBoardCad) : 0,
                            InvPriceSingleSupCad = invrow.InvPriceSingleSupCad != null ? Convert.ToDecimal(invrow.InvPriceSingleSupCad) : 0,
                        });
                }
                var GirData = QuotaManager.SaveGirGroupInvoice(GirGrBData, User.Identity.Name);
                var GirGroupVModel = InitQuotaCreateGirGroupViewModel(GirData, model.IsGir, model.AddGirSelCustomerID);
                if (GirData.Error != null)
                    GirGroupVModel.GrActionMessage = GirData.Error.Message == null ? "Successfully saved" : GirData.Error.Message;
                this.SetPermission(GirGroupVModel, AllPermVModel);
                return PartialView("QuotationGirGroupGrid", GirGroupVModel);
            }
            return PartialView();
            
        }
        [Authorize]
        [HttpPost]
        public JsonResult QuotationCreateGroupValidation(string ArrivalDate)
        {
            bool Valid = true;
            if (ArrivalDate != null && ArrivalDate != "")
            {
                try
                {
                    var DateTimeFromModel = Convert.ToDateTime(ArrivalDate);
                    if (DateTime.Compare(DateTimeFromModel, DateTime.Now) < 0)
                    {
                        Valid = false;
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.ToMessageAndCompleteStacktrace());
                    Valid = false;
                }
            }
            else
            {
                Valid = false;
            }

            return this.Json(Valid);
        }

        #endregion

        #region Data Inits
        private QuotationGroupBData InitQuotaSaveGroupBData(QuotationGroupDetailViewModel model)
        {
            QuotationGroupBData GroupBData = new QuotationGroupBData()
            {
                GroupCode = model.GroupCode,
                GroupID = model.GroupID,
                QuotaID = model.QuotaID,
                GroupName = model.GroupName,
                CustomerID = model.CustomerID,
                SeasonID = model.SeasonID,
                GroupEstPax = model.GroupEstPax != null ? Convert.ToInt16(model.GroupEstPax) : (short?)null,
                GroupEstRoom = model.GroupEstRooms != null ? Convert.ToInt16(model.GroupEstRooms) : (short?)null,
            };
            return GroupBData;
        }
        private QuotationGirGroupGridViewModel InitQuotaCreateGirGroupViewModel(QuotationGirGroupGridBData GirData, bool Gir, string CustomerID)
        {
            QuotationGirGroupGridViewModel GirGroupVModel = new QuotationGirGroupGridViewModel();
            GirGroupVModel.GroupStatus = new List<System.Web.WebPages.Html.SelectListItem>();
            GirGroupVModel.GroupCountry = new List<System.Web.WebPages.Html.SelectListItem>();
            GirGroupVModel.Employee = new List<System.Web.WebPages.Html.SelectListItem>();
            GirGroupVModel.AddGirGroupID = GirData.GroupID;
            GirGroupVModel.AddGirGroupCode = GirData.GroupID.ToString();
            if (CustomerID != null)
            {
                GirGroupVModel.AddGirSelCustomerID = CustomerID;
            }
            GirGroupVModel.IsGir = Gir;
            if (GirData.Error != null)
                GirGroupVModel.GrActionMessage = GirData.Error.Message == null ? "Group successfully created." : GirData.Error.Message;
            GirGroupVModel.Rows = new List<QuotationGirGroupGridRowViewModel>();
            if (Gir)
            {
                GirGroupVModel.AddGirCustomer = GirData.Customer;
                GirGroupVModel.AddGirMainCustomerID = GirData.SelCustomerID.ToString();
                GirGroupVModel.AddInvGroups = new List<System.Web.WebPages.Html.SelectListItem>();
                if (GirData.InvGirGroups != null)
                {
                    foreach (var InvGr in GirData.InvGirGroups)
                        GirGroupVModel.AddInvGroups.Add(new System.Web.WebPages.Html.SelectListItem
                        {
                            Text = InvGr.Value,
                            Value = InvGr.Key.ToString()
                        });
                }
                GirGroupVModel.InvRows = new List<QuotationGirInvoiceGridRowViewModel>();
                if (GirData.InvRows != null)
                {
                    foreach (var invrow in GirData.InvRows)
                        GirGroupVModel.InvRows.Add(new QuotationGirInvoiceGridRowViewModel
                        {
                            InvPax = invrow.InvPax,
                            InvGroupID = invrow.InvGroupID,
                            InvGroupCode = invrow.InvGroupCode,
                            InvGroupName = invrow.InvGroupName,
                            InvCustomer = invrow.InvCustomer,
                            InvCustomerID = invrow.InvCustomerID.ToString(),
                            InvArrivalDate = invrow.InvArrivalDate != null ? Convert.ToDateTime(invrow.InvArrivalDate).ToString("dd/MMM/yy") : "",
                            InvPricePerPerson = invrow.InvPricePerPerson != null ? Convert.ToDecimal(invrow.InvPricePerPerson).ToString("F") : "",
                            InvPriceFBoard = invrow.InvPriceFBoard != null ? Convert.ToDecimal(invrow.InvPriceFBoard).ToString("F") : "",
                            InvPriceSingleSup = invrow.InvPriceSingleSup != null ? Convert.ToDecimal(invrow.InvPriceSingleSup).ToString("F") : "",
                            InvPricePerPersonCad = invrow.InvPricePerPersonCad != null ? Convert.ToDecimal(invrow.InvPricePerPersonCad).ToString("F") : "",
                            InvPriceFBoardCad = invrow.InvPriceFBoardCad != null ? Convert.ToDecimal(invrow.InvPriceFBoardCad).ToString("F") : "",
                            InvPriceSingleSupCad = invrow.InvPriceSingleSupCad != null ? Convert.ToDecimal(invrow.InvPriceSingleSupCad).ToString("F") : "",
                        });
                }
            }
            if (GirData.Rows != null)
            {
                foreach (var rowdata in GirData.Rows)
                    GirGroupVModel.Rows.Add(new QuotationGirGroupGridRowViewModel()
                    {
                        IsPushed = rowdata.IsPushed != null ? Convert.ToBoolean(rowdata.IsPushed) : false,
                        AsGir = Convert.ToBoolean(rowdata.AsGir),
                        GirGroupID = rowdata.GroupID,
                        GirGroupName = rowdata.GroupName,
                        GirGroupCode = rowdata.GroupCode,
                        GirCustomer = rowdata.Customer,
                        GirSelCustomerID = rowdata.SelCustomerID.ToString(),
                        GirArrivalDate = rowdata.ArrivalDate != null ? Convert.ToDateTime(rowdata.ArrivalDate).ToString("dd/MMM/yy") : "",
                        GirDepartureDate = rowdata.DepartureDate != null ? Convert.ToDateTime(rowdata.DepartureDate).ToString("dd/MMM/yy") : "",
                        GirPax = rowdata.Pax.ToString(),
                        GirRoom = rowdata.Room.ToString(),
                        GirNoNights = rowdata.ArrivalDate != null && rowdata.DepartureDate != null ? ((Convert.ToDateTime(rowdata.DepartureDate) - Convert.ToDateTime(rowdata.ArrivalDate)).Days).ToString() : null,
                        GirSelStatusID = rowdata.SelStatusID.ToString(),
                        GirSelCountryID = rowdata.SelCountryID.ToString(),
                        GirCancelInfo = rowdata.CancelInfo,
                    });
            }
            if (GirData.Status != null)
            {
                foreach (var st in GirData.Status)
                    GirGroupVModel.GroupStatus.Add(new System.Web.WebPages.Html.SelectListItem()
                        {
                            Text = st.Value,
                            Value = st.Key.ToString()
                        });
            }
            if (GirData.Country != null)
            {
                foreach (var ctr in GirData.Country)
                    GirGroupVModel.GroupCountry.Add(new System.Web.WebPages.Html.SelectListItem()
                    {
                        Text = ctr.Value,
                        Value = ctr.Key.ToString(),
                    });
            }
            if (GirData.Employee != null)
            {
                foreach (var emp in GirData.Employee)
                    GirGroupVModel.Employee.Add(new System.Web.WebPages.Html.SelectListItem()
                    {
                        Text = emp.Value,
                        Value = emp.Key.ToString(),
                    });
            }
            return GirGroupVModel;
        }

        private QuotationDetailsBData InitQuotaDetailsBData(QuotationDetailViewModel model)
        {
            QuotationDetailsBData QuotaBdata = new QuotationDetailsBData();
            try
            {
                QuotaBdata.QuotaID = Convert.ToInt32(model.QuotaID);
                QuotaBdata.Accepted = model.QuotaConfirmed;
                QuotaBdata.IsGir = model.GroupIsGir;
                QuotaBdata.SelectedQuotaCountry = model.SelQuotaCountry != null ? Convert.ToInt16(model.SelQuotaCountry) : (short?)null;
                QuotaBdata.NoOfFlights = Convert.ToByte(model.NoOfFlights);
                QuotaBdata.SelectedRegion = model.SelectedRegion;
                QuotaBdata.QuotaCode = model.QuotaCode;
                QuotaBdata.SelectedCustomerId = Convert.ToInt32(model.SelectedCustomerId);
                QuotaBdata.SelectedSeason = Convert.ToInt32(model.SelectedSeason);
                QuotaBdata.QuotaName = model.QuotaName;
                QuotaBdata.SelectedEmployeeId = Convert.ToInt32(model.SelectedEmployeeId);
                QuotaBdata.NoNights = Convert.ToByte(model.NoNights);
                QuotaBdata.SelectedArrivalCity = model.SelectedArrivalCity;
                QuotaBdata.ArrivalDate = model.ArrivalDate != null ? Convert.ToDateTime(model.ArrivalDate):(DateTime?)null;
                QuotaBdata.QuotaDate = Convert.ToDateTime(model.QuotaDate);
                QuotaBdata.NoOfMeals = Convert.ToByte(model.NoOfMeals);
                if (model.ArrivalDate != null && model.NoNights != null)
                    QuotaBdata.DepartureDate = Convert.ToDateTime(model.ArrivalDate).AddDays(Convert.ToInt32(model.NoNights));
                QuotaBdata.SelectedDepartureCity = model.SelectedDepartureCity;
                QuotaBdata.LastUpDate = Convert.ToDateTime(model.LastUpDate);
                QuotaBdata.MaxNoOfPax = Convert.ToInt16(model.MaxNoOfPax);
                QuotaBdata.MinNoOfPax = Convert.ToDouble(model.MinNoOfPax);
                QuotaBdata.IncNoOfPax = Convert.ToInt16(model.IncNoOfPax);
                QuotaBdata.HFreeRoom = Convert.ToInt16(model.HFreeRoom);
                QuotaBdata.HForPaid = Convert.ToInt16(model.HForPaid);
                QuotaBdata.SelectedFreeCalcType = Convert.ToInt16(model.SelectedFreeCalcType);
                QuotaBdata.profit = Convert.ToDouble(model.profit);
                QuotaBdata.OFreeService = Convert.ToInt16(model.OFreeService);
                QuotaBdata.OForPaid = Convert.ToInt16(model.OForPaid);
                QuotaBdata.Proposal = model.Proposal;
                QuotaBdata.QuotaNote = model.QuotaNote;
            }
            catch(Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
            }
            return QuotaBdata;
        }
        private List<QuotaHotelGridRowBData> InitQuotaHotelGridBData(QuotationHotelGridViewModel model)
        {
            List<QuotaHotelGridRowBData> QuotaGridBdata = new List<QuotaHotelGridRowBData>();
            if (QuotaGridBdata != null)
            {
                foreach (var row in model.Rows)
                    try
                    {
                        QuotaGridBdata.Add(new QuotaHotelGridRowBData
                        {
                            BFreeFlag = row.BFreeFlag,
                            BGuideFlag = row.BGuideFlag,
                            Breakfast = Convert.ToDecimal(row.Breakfast),
                            BrfType = row.BrfType,
                            DriverFlag = row.DriverFlag,
                            FreeFlag = row.FreeFlag,
                            GuideFlag = row.GuideFlag,
                            HotelDesc = row.HotelDesc,
                            HotelMFlag = row.HotelM,
                            LineNo = Convert.ToInt16(row.LineNo),
                            Luggage = Convert.ToDecimal(row.Luggage),
                            Nights = Convert.ToInt16(row.Nights),
                            OccTax = Convert.ToDecimal(row.OccTax),
                            Room = Convert.ToDecimal(row.Room),
                            tax = Convert.ToDouble(row.tax),
                            QuotaID = Convert.ToInt32(row.QuotaID),
                            VendorID = row.VendorID != null ? Convert.ToInt32(row.VendorID) : (int?)null,
                            Currency = row.CurrencyHotel,
                            LineDate = Convert.ToDateTime(row.LineDate),
                        });


                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.ToMessageAndCompleteStacktrace());
                    }
            }
            return QuotaGridBdata;
        }
        private List<QuotaLunchDinnerGridRowBData> InitQuotaLunchDinnerGridBData(QuotationLunchDinnerGridViewModel model)
        {
            List<QuotaLunchDinnerGridRowBData> QuotaGridBdata = new List<QuotaLunchDinnerGridRowBData>();
            if (model.Rows != null)
            {
                foreach (var row in model.Rows)
                    try
                    {
                        QuotaGridBdata.Add(new QuotaLunchDinnerGridRowBData
                        {
                            FreeFlag = row.FreeFlag,
                            GuideFlag = row.GuideFlag,
                            Cost = Convert.ToDecimal(row.Cost),
                            CostD = Convert.ToDecimal(row.CostD),
                            Description = row.DescriptionLunch,
                            DescriptionD = row.DescriptionLunchD,
                            LunchMFlag = row.LunchMFlag,
                            DinnerMFlag = row.DinnerMFlag,
                            LunchVendorID = row.LunchVendorID != null ? Convert.ToInt32(row.LunchVendorID) : (int?)null,
                            DinnerVendorID = row.DinnerVendorID != null ? Convert.ToInt32(row.DinnerVendorID) : (int?)null,
                            FreeFlagD = row.FreeFlagD,
                            GuideFlagD = row.GuideFlagD,
                            Day = Convert.ToByte(row.Day),
                            LineNo = Convert.ToInt16(row.LineNo),
                            QuotaID = Convert.ToInt32(row.QuotaID),
                            Currency = row.CurrencyLunchDinner,
                            LineDate = Convert.ToDateTime(row.LineDate),
                        });
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.ToMessageAndCompleteStacktrace());
                    }
            }
            return QuotaGridBdata;
        }
        private List<QuotaEntranceGridRowBData> InitQuotaEntranceGridBData(QuotationEntranceGridViewModel model)
        {
            List<QuotaEntranceGridRowBData> QuotaGridBdata = new List<QuotaEntranceGridRowBData>();
            if (model.Rows != null)
            {
                foreach (var row in model.Rows)
                    try
                    {
                        QuotaGridBdata.Add(new QuotaEntranceGridRowBData
                        {
                            VendorID = row.VendorID != null ? Convert.ToInt32(row.VendorID) : (int?)null,
                            FreeFlag = row.FreeFlag,
                            GuideFlag = row.GuideFlag,
                            Cost = Convert.ToDecimal(row.Cost),
                            CostG = Convert.ToDecimal(row.CostG),
                            Description = row.DescriptionEntrance,
                            LineNo = Convert.ToInt16(row.LineNo),
                            QuotaID = Convert.ToInt32(row.QuotaID),
                            Day = Convert.ToByte(row.Day),
                            Currency = row.CurrencyEntrance,
                            EntranceMFlag = row.EntranceMFlag,
                            LineDate = Convert.ToDateTime(row.LineDate)
                        });
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.ToMessageAndCompleteStacktrace());
                    }
            }
            return QuotaGridBdata;
        }
        private List<QuotaMiscGridRowBData> InitQuotaMiscGridBData(QuotationMiscGridViewModel model)
        {
            List<QuotaMiscGridRowBData> QuotaGridBdata = new List<QuotaMiscGridRowBData>();
            if (model.Rows != null)
            {
                foreach (var row in model.Rows)
                    try
                    {
                        QuotaGridBdata.Add(new QuotaMiscGridRowBData
                        {
                            Cost = Convert.ToDecimal(row.Cost),
                            CostG = Convert.ToDecimal(row.CostG),
                            Description = row.Description,
                            LineNo = Convert.ToInt16(row.LineNo),
                            QuotaID = Convert.ToInt32(row.QuotaID),
                            Day = Convert.ToByte(row.Day),
                            Currency = row.CurrencyMisc,
                            PlaneFlag = row.Plane,
                        });
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.ToMessageAndCompleteStacktrace());
                    }
            }
            return QuotaGridBdata;
        }
        private List<QuotaBusGridRowBData> InitQuotaBusGridBData(QuotationBusGridViewModel model)
        {
            List<QuotaBusGridRowBData> QuotaGridBdata = new List<QuotaBusGridRowBData>();
            if (model.Rows != null)
            {
                foreach (var row in model.Rows)
                    try
                    {
                        QuotaGridBdata.Add(new QuotaBusGridRowBData
                        {
                            VendorID = Convert.ToInt32(row.VendorID),
                            Cost = Convert.ToDecimal(row.Cost),
                            Rate = Convert.ToDecimal(row.Rate),
                            Description = row.DescriptionBus,
                            LineNo = Convert.ToInt16(row.LineNo),
                            // Qty to 1
                            Qty = 1,
                            //Qty = Convert.ToInt16(row.Qty),
                            QuotaID = Convert.ToInt32(row.QuotaID),
                            Day = Convert.ToByte(row.Day),
                            DayQty = Convert.ToByte(row.DayQty),
                            Currency = row.CurrencyBus,
                            BusMFlag = row.BusMFlag,
                            ServiceID = row.SelectedServiceID != null ? Convert.ToInt32(row.SelectedServiceID) : (int?)null,
                            LineDate = Convert.ToDateTime(row.LineDate),
                        });
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.ToMessageAndCompleteStacktrace());
                    }
            }
            return QuotaGridBdata;
        }
        private List<QuotaGuideGridRowBData> InitQuotaGuideGridBData(QuotationGuideGridViewModel model)
        {
            List<QuotaGuideGridRowBData> QuotaGridBdata = new List<QuotaGuideGridRowBData>();
            if (model.Rows != null)
            {
                foreach (var row in model.Rows)
                    try
                    {
                        QuotaGridBdata.Add(new QuotaGuideGridRowBData
                        {
                            GuideID = Convert.ToInt32(row.GuideID),
                            Cost = Convert.ToDecimal(row.Cost),
                            Rate = Convert.ToDecimal(row.Rate),
                            Description = row.DescriptionGuide,
                            LineNo = Convert.ToInt16(row.LineNo),
                            // Qty to 1
                            Qty = 1,
                            // Qty = Convert.ToInt16(row.Qty),
                            QuotaID = Convert.ToInt32(row.QuotaID),
                            Day = Convert.ToByte(row.Day),
                            DayQty = Convert.ToByte(row.DayQty),
                            Currency = row.CurrencyGuide,
                            GuideMFlag = row.GuideMFlag,
                            ServiceID = row.SelectedServiceID != null ? Convert.ToInt32(row.SelectedServiceID) : (int?)null,
                        });
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.ToMessageAndCompleteStacktrace());
                    }
            }
            return QuotaGridBdata;
        }
        private QuotationDetailViewModel LoadQuotationDetailsDatainit(string QuotaId)
        {
            QuotationDetailViewModel QuotaDetVModel = new QuotationDetailViewModel();
            QuotaDetVModel.QuotaCountry = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.Region = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.Season = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.ArrivalCity = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.EmployeeId = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.CustomerId = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.DepartureCity = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.FreeCalcType = new List<System.Web.WebPages.Html.SelectListItem>()
                {
                    new System.Web.WebPages.Html.SelectListItem(){Text="No Free", Value = "0"},
                    new System.Web.WebPages.Html.SelectListItem(){Text="1 Pax in Dbl Free", Value = "1"},
                    new System.Web.WebPages.Html.SelectListItem(){Text="Single Free", Value = "2"},
                };
            // 3 types of free calc

            QuotaManager = new QuotationManager();
            var QuotaDetBdata = QuotaManager.GetQuotationBDataByQuotaId(QuotaId, User.Identity.Name);
            // data inits
           
            // Country
            if (QuotaDetBdata != null)
            {
                 // group info
                if (QuotaDetVModel.GroupCode != null)
                {
                    QuotaDetVModel.GroupID = QuotaDetBdata.GroupID.ToString();
                    QuotaDetVModel.GroupCode = QuotaDetBdata.GroupCode;
                    QuotaDetVModel.GroupName = QuotaDetBdata.GroupName;
                }
                if (QuotaDetBdata.QuotaCountry != null)
                {
                    foreach (var type in QuotaDetBdata.QuotaCountry)
                        QuotaDetVModel.QuotaCountry.Add(new System.Web.WebPages.Html.SelectListItem() { Text = type.Value, Value = type.Key.ToString() });
                }
                // region
                if (QuotaDetBdata.Region != null)
                {
                    foreach (var region in QuotaDetBdata.Region)
                        QuotaDetVModel.Region.Add(new System.Web.WebPages.Html.SelectListItem() { Text = region.Value, Value = region.Value });
                }
                // customer
                // QuotaDetVModel.CustomerId.Add(new System.Web.WebPages.Html.SelectListItem() { Text = "", Value = "0" });
                if (QuotaDetBdata.CustomerId != null)
                {
                    foreach (var cust in QuotaDetBdata.CustomerId)
                    {
                        QuotaDetVModel.CustomerId.Add(new System.Web.WebPages.Html.SelectListItem() { Text = cust.Value, Value = cust.Key.ToString() });
                    }
                }
                // Season
                if (QuotaDetBdata.Season != null)
                {
                    foreach (var season in QuotaDetBdata.Season)
                        QuotaDetVModel.Season.Add(new System.Web.WebPages.Html.SelectListItem() { Text = season.Value, Value = season.Key.ToString() });
                }
                // Employee
                if (QuotaDetBdata.Employee != null)
                {
                    foreach (var empl in QuotaDetBdata.Employee)
                        QuotaDetVModel.EmployeeId.Add(new System.Web.WebPages.Html.SelectListItem() { Text = empl.Value, Value = empl.Key.ToString() });
                }
                // arrival city
                if (QuotaDetBdata.ArrivalCity != null)
                {
                    foreach (var arrcity in QuotaDetBdata.ArrivalCity)
                        QuotaDetVModel.ArrivalCity.Add(new System.Web.WebPages.Html.SelectListItem() { Text = arrcity.Value, Value = arrcity.Value });
                }
                // departure city
                if (QuotaDetBdata.DepartureCity != null)
                {
                    foreach (var depcity in QuotaDetBdata.DepartureCity)
                        QuotaDetVModel.DepartureCity.Add(new System.Web.WebPages.Html.SelectListItem() { Text = depcity.Value, Value = depcity.Value });
                }

                QuotaDetVModel.QuotaID = QuotaDetBdata.QuotaID.ToString();
                QuotaDetVModel.QuotaConfirmed = QuotaDetBdata.Accepted == null ? false : Convert.ToBoolean(QuotaDetBdata.Accepted);
                QuotaDetVModel.GroupIsGir = QuotaDetBdata.IsGir == null ? false : Convert.ToBoolean(QuotaDetBdata.IsGir);
                QuotaDetVModel.SelQuotaCountry = QuotaDetBdata.SelectedQuotaCountry.ToString();
                QuotaDetVModel.NoOfFlights = QuotaDetBdata.NoOfFlights.ToString();
                QuotaDetVModel.SelectedRegion = QuotaDetBdata.SelectedRegion;
                QuotaDetVModel.QuotaCode = QuotaDetBdata.QuotaCode;
                QuotaDetVModel.SelectedCustomerId = QuotaDetBdata.SelectedCustomerId.ToString();
                QuotaDetVModel.SelectedSeason = QuotaDetBdata.SelectedSeason.ToString();
                QuotaDetVModel.QuotaName = QuotaDetBdata.QuotaName;
                QuotaDetVModel.SelectedEmployeeId = QuotaDetBdata.SelectedEmployeeId.ToString();
                QuotaDetVModel.NoNights = QuotaDetBdata.NoNights.ToString();
                QuotaDetVModel.NoOfMeals = QuotaDetBdata.NoOfMeals.ToString();
                QuotaDetVModel.ArrivalDate = QuotaDetBdata.ArrivalDate==null?"": Convert.ToDateTime(QuotaDetBdata.ArrivalDate).ToString("ddd, dd/MMM/yy");
                QuotaDetVModel.QuotaDate = Convert.ToDateTime(QuotaDetBdata.QuotaDate).ToString("ddd, dd/MMM/yy");
                QuotaDetVModel.LastUpDate = Convert.ToDateTime(QuotaDetBdata.LastUpDate).ToString("ddd, dd/MMM/yy");
                QuotaDetVModel.QuotaNote = QuotaDetBdata.QuotaNote;
                QuotaDetVModel.MaxNoOfPax = QuotaDetBdata.MaxNoOfPax.ToString();
                QuotaDetVModel.MinNoOfPax = QuotaDetBdata.MinNoOfPax.ToString();
                QuotaDetVModel.IncNoOfPax = QuotaDetBdata.IncNoOfPax.ToString();
                QuotaDetVModel.HFreeRoom = QuotaDetBdata.HFreeRoom.ToString();
                QuotaDetVModel.HForPaid = QuotaDetBdata.HForPaid.ToString();
                QuotaDetVModel.DepartureDate = QuotaDetBdata.DepartureDate == null ? null : Convert.ToDateTime(QuotaDetBdata.DepartureDate).ToString("ddd, dd/MMM/yy");
                QuotaDetVModel.SelectedDepartureCity = QuotaDetBdata.SelectedDepartureCity;
                QuotaDetVModel.profit = QuotaDetBdata.profit.ToString("#.000");
                QuotaDetVModel.OFreeService = QuotaDetBdata.OFreeService.ToString();
                QuotaDetVModel.OForPaid = QuotaDetBdata.OForPaid.ToString();
                QuotaDetVModel.Proposal = QuotaDetBdata.Proposal;
                QuotaDetVModel.SelectedArrivalCity = QuotaDetBdata.SelectedArrivalCity;
                QuotaDetVModel.SelectedFreeCalcType = QuotaDetBdata.SelectedFreeCalcType.ToString();
            }
            return QuotaDetVModel;
        }
        private QuotationDetailViewModel LoadQuotationDetailsSaveAsDatainit(QuotationDetailsBData QuotaDetBdata)
        {
            QuotationDetailViewModel QuotaDetVModel = new QuotationDetailViewModel();
            QuotaDetVModel.QuotaCountry = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.Region = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.Season = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.ArrivalCity = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.EmployeeId = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.CustomerId = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.DepartureCity = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.FreeCalcType = new List<System.Web.WebPages.Html.SelectListItem>()
                {
                    new System.Web.WebPages.Html.SelectListItem(){Text="No Free", Value = "0"},
                    new System.Web.WebPages.Html.SelectListItem(){Text="1 Pax in Dbl Free", Value = "1"},
                    new System.Web.WebPages.Html.SelectListItem(){Text="Single Free", Value = "2"},
                };
            // 3 types of free calc
    
            // data inits
            // Country
            if (QuotaDetBdata != null)
            {
                if (QuotaDetBdata.QuotaCountry != null)
                {
                    foreach (var type in QuotaDetBdata.QuotaCountry)
                        QuotaDetVModel.QuotaCountry.Add(new System.Web.WebPages.Html.SelectListItem() { Text = type.Value, Value = type.Key.ToString() });
                }
                // region
                if (QuotaDetBdata.Region != null)
                {
                    foreach (var region in QuotaDetBdata.Region)
                        QuotaDetVModel.Region.Add(new System.Web.WebPages.Html.SelectListItem() { Text = region.Value, Value = region.Value });
                }
                // customer
                if (QuotaDetBdata.CustomerId != null)
                {
                    foreach (var cust in QuotaDetBdata.CustomerId)
                    {
                        QuotaDetVModel.CustomerId.Add(new System.Web.WebPages.Html.SelectListItem() { Text = cust.Value, Value = cust.Key.ToString() });
                    }
                }
                // Season
                if (QuotaDetBdata.Season != null)
                {
                    foreach (var season in QuotaDetBdata.Season)
                        QuotaDetVModel.Season.Add(new System.Web.WebPages.Html.SelectListItem() { Text = season.Value, Value = season.Key.ToString() });
                }
                // Employee
                if (QuotaDetBdata.Employee != null)
                {
                    foreach (var empl in QuotaDetBdata.Employee)
                        QuotaDetVModel.EmployeeId.Add(new System.Web.WebPages.Html.SelectListItem() { Text = empl.Value, Value = empl.Key.ToString() });
                }
                // arrival city
                if (QuotaDetBdata.ArrivalCity != null)
                {
                    foreach (var arrcity in QuotaDetBdata.ArrivalCity)
                        QuotaDetVModel.ArrivalCity.Add(new System.Web.WebPages.Html.SelectListItem() { Text = arrcity.Value, Value = arrcity.Value });
                }
                // departure city
                if (QuotaDetBdata.DepartureCity != null)
                {
                    foreach (var depcity in QuotaDetBdata.DepartureCity)
                        QuotaDetVModel.DepartureCity.Add(new System.Web.WebPages.Html.SelectListItem() { Text = depcity.Value, Value = depcity.Value });
                }

                QuotaDetVModel.QuotaID = QuotaDetBdata.QuotaID.ToString();
                QuotaDetVModel.QuotaConfirmed = QuotaDetBdata.Accepted == null ? false : Convert.ToBoolean(QuotaDetBdata.Accepted);
                QuotaDetVModel.GroupIsGir = QuotaDetBdata.IsGir == null ? false : Convert.ToBoolean(QuotaDetBdata.IsGir);
                QuotaDetVModel.SelQuotaCountry = QuotaDetBdata.SelectedQuotaCountry.ToString();
                QuotaDetVModel.NoOfFlights = QuotaDetBdata.NoOfFlights.ToString();
                QuotaDetVModel.SelectedRegion = QuotaDetBdata.SelectedRegion;
                QuotaDetVModel.QuotaCode = QuotaDetBdata.QuotaCode;
                QuotaDetVModel.SelectedCustomerId = QuotaDetBdata.SelectedCustomerId.ToString();
                QuotaDetVModel.SelectedSeason = QuotaDetBdata.SelectedSeason.ToString();
                QuotaDetVModel.QuotaName = QuotaDetBdata.QuotaName;
                QuotaDetVModel.SelectedEmployeeId = QuotaDetBdata.SelectedEmployeeId.ToString();
                QuotaDetVModel.NoNights = QuotaDetBdata.NoNights.ToString();
                QuotaDetVModel.NoOfMeals = QuotaDetBdata.NoOfMeals.ToString();
                QuotaDetVModel.ArrivalDate = QuotaDetBdata.ArrivalDate == null ? null : Convert.ToDateTime(QuotaDetBdata.ArrivalDate).ToString("ddd, dd/MMM/yy");
                QuotaDetVModel.QuotaDate = Convert.ToDateTime(QuotaDetBdata.QuotaDate).ToString("ddd, dd/MMM/yy");
                QuotaDetVModel.LastUpDate = Convert.ToDateTime(QuotaDetBdata.LastUpDate).ToString("ddd, dd/MMM/yy");
                QuotaDetVModel.QuotaNote = QuotaDetBdata.QuotaNote;
                QuotaDetVModel.MaxNoOfPax = QuotaDetBdata.MaxNoOfPax.ToString();
                QuotaDetVModel.MinNoOfPax = QuotaDetBdata.MinNoOfPax.ToString();
                QuotaDetVModel.IncNoOfPax = QuotaDetBdata.IncNoOfPax.ToString();
                QuotaDetVModel.HFreeRoom = QuotaDetBdata.HFreeRoom.ToString();
                QuotaDetVModel.HForPaid = QuotaDetBdata.HForPaid.ToString();
                QuotaDetVModel.DepartureDate = QuotaDetBdata.DepartureDate == null ? null : Convert.ToDateTime(QuotaDetBdata.DepartureDate).ToString("ddd, dd/MMM/yy");
                QuotaDetVModel.SelectedDepartureCity = QuotaDetBdata.SelectedDepartureCity;
                QuotaDetVModel.profit = QuotaDetBdata.profit.ToString("#.000");
                QuotaDetVModel.OFreeService = QuotaDetBdata.OFreeService.ToString();
                QuotaDetVModel.OForPaid = QuotaDetBdata.OForPaid.ToString();
                QuotaDetVModel.Proposal = QuotaDetBdata.Proposal;
                QuotaDetVModel.SelectedArrivalCity = QuotaDetBdata.SelectedArrivalCity;
                QuotaDetVModel.SelectedFreeCalcType = QuotaDetBdata.SelectedFreeCalcType.ToString();
            }
            return QuotaDetVModel;
        }
        private QuotationDetailViewModel NewQuotationDetailsDatainit()
        {
            QuotationDetailViewModel QuotaDetVModel = new QuotationDetailViewModel();
            QuotaDetVModel.QuotaCountry = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.Region = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.Season = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.ArrivalCity = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.EmployeeId = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.CustomerId = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.DepartureCity = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaDetVModel.FreeCalcType = new List<System.Web.WebPages.Html.SelectListItem>()
                {
                    new System.Web.WebPages.Html.SelectListItem(){Text="No Free", Value = "0"},
                    new System.Web.WebPages.Html.SelectListItem(){Text="1 Pax in Dbl Free", Value = "1"},
                    new System.Web.WebPages.Html.SelectListItem(){Text="Single Free", Value = "2"},
                };
            // 3 types of free calc

            QuotaManager = new QuotationManager();
            var QuotaDetBdata = QuotaManager.NewQuotationBData(User.Identity.Name);
            // data inits
            // Country
            if (QuotaDetBdata.QuotaCountry != null)
            {
                foreach (var ctr in QuotaDetBdata.QuotaCountry)
                    QuotaDetVModel.QuotaCountry.Add(new System.Web.WebPages.Html.SelectListItem() { Text = ctr.Value, Value = ctr.Key.ToString() });
            }
            // region
            if (QuotaDetBdata.Region != null)
            {
                foreach (var region in QuotaDetBdata.Region)
                    QuotaDetVModel.Region.Add(new System.Web.WebPages.Html.SelectListItem() { Text = region.Value, Value = region.Value });
            }
            // customer 
            if (QuotaDetBdata.CustomerId != null)
            {
                foreach (var cust in QuotaDetBdata.CustomerId)
                {
                    QuotaDetVModel.CustomerId.Add(new System.Web.WebPages.Html.SelectListItem() { Text = cust.Value, Value = cust.Key.ToString() });
                }
            }
            // Season
            if (QuotaDetBdata.Season != null)
            {
                foreach (var season in QuotaDetBdata.Season)
                    QuotaDetVModel.Season.Add(new System.Web.WebPages.Html.SelectListItem() { Text = season.Value, Value = season.Key.ToString() });
            }
            // Employee
            if (QuotaDetBdata.Employee != null)
            {
                foreach (var empl in QuotaDetBdata.Employee)
                    QuotaDetVModel.EmployeeId.Add(new System.Web.WebPages.Html.SelectListItem() { Text = empl.Value, Value = empl.Key.ToString() });
            }
            // arrival city
            if (QuotaDetBdata.ArrivalCity != null)
            {
                foreach (var arrcity in QuotaDetBdata.ArrivalCity)
                    QuotaDetVModel.ArrivalCity.Add(new System.Web.WebPages.Html.SelectListItem() { Text = arrcity.Value, Value = arrcity.Value });
            }
            // departure city
            if (QuotaDetBdata.DepartureCity != null)
            {
                foreach (var depcity in QuotaDetBdata.DepartureCity)
                    QuotaDetVModel.DepartureCity.Add(new System.Web.WebPages.Html.SelectListItem() { Text = depcity.Value, Value = depcity.Value });
            }
            QuotaDetVModel.QuotaID = QuotaDetVModel.QuotaIden = QuotaDetBdata.QuotaID.ToString();
            QuotaDetVModel.QuotaConfirmed = QuotaDetBdata.Accepted == null ? false : Convert.ToBoolean(QuotaDetBdata.Accepted);
            QuotaDetVModel.GroupIsGir = QuotaDetBdata.IsGir == null ? false : Convert.ToBoolean(QuotaDetBdata.IsGir);
            QuotaDetVModel.SelQuotaCountry = QuotaDetBdata.SelectedQuotaCountry.ToString();
            QuotaDetVModel.NoOfFlights = QuotaDetBdata.NoOfFlights.ToString();
            QuotaDetVModel.SelectedRegion = QuotaDetBdata.SelectedRegion;
            QuotaDetVModel.QuotaCode = QuotaDetBdata.QuotaCode;
            QuotaDetVModel.SelectedCustomerId = QuotaDetBdata.SelectedCustomerId.ToString();
            QuotaDetVModel.SelectedSeason = QuotaDetBdata.SelectedSeason.ToString();
            QuotaDetVModel.QuotaName = QuotaDetBdata.QuotaName;
            QuotaDetVModel.SelectedEmployeeId = QuotaDetBdata.SelectedEmployeeId.ToString();
            QuotaDetVModel.NoNights = QuotaDetBdata.NoNights.ToString();
            QuotaDetVModel.NoOfMeals = QuotaDetBdata.NoOfMeals.ToString();
            QuotaDetVModel.ArrivalDate = QuotaDetBdata.ArrivalDate == null ? null : Convert.ToDateTime(QuotaDetBdata.ArrivalDate).ToString("ddd, dd/MMM/yy");
            QuotaDetVModel.QuotaDate = Convert.ToDateTime(QuotaDetBdata.QuotaDate).ToString("ddd, dd/MMM/yy");
            QuotaDetVModel.LastUpDate = Convert.ToDateTime(QuotaDetBdata.LastUpDate).ToString("ddd, dd/MMM/yy");
            QuotaDetVModel.QuotaNote = QuotaDetBdata.QuotaNote;
            QuotaDetVModel.MaxNoOfPax = QuotaDetBdata.MaxNoOfPax.ToString();
            QuotaDetVModel.MinNoOfPax = QuotaDetBdata.MinNoOfPax.ToString();
            QuotaDetVModel.IncNoOfPax = QuotaDetBdata.IncNoOfPax.ToString();
            QuotaDetVModel.HFreeRoom = QuotaDetBdata.HFreeRoom.ToString();
            QuotaDetVModel.HForPaid = QuotaDetBdata.HForPaid.ToString();
            QuotaDetVModel.DepartureDate = QuotaDetBdata.DepartureDate == null ? null : Convert.ToDateTime(QuotaDetBdata.DepartureDate).ToString("ddd, dd/MMM/yy");
            QuotaDetVModel.SelectedDepartureCity = QuotaDetBdata.SelectedDepartureCity;
            QuotaDetVModel.profit = QuotaDetBdata.profit.ToString("#.000");
            QuotaDetVModel.OFreeService = QuotaDetBdata.OFreeService.ToString();
            QuotaDetVModel.OForPaid = QuotaDetBdata.OForPaid.ToString();
            QuotaDetVModel.Proposal = QuotaDetBdata.Proposal;
            QuotaDetVModel.SelectedArrivalCity = QuotaDetBdata.SelectedArrivalCity;
            QuotaDetVModel.SelectedFreeCalcType = QuotaDetBdata.SelectedFreeCalcType.ToString();
            return QuotaDetVModel;
        }

        private QuotationHotelGridViewModel LoadQuotationHotelGridDatainit(string QuotaId)
        {
            QuotationHotelGridViewModel QuotaHotelVModel = new QuotationHotelGridViewModel();
            QuotaHotelVModel.Rows = new List<QuotationHotelGridRowViewModel>();
            QuotaManager = new QuotationManager();
            var QuotaHotelBdata = QuotaManager.LoadQuotaHotelGrid(QuotaId);
            if (QuotaHotelBdata.GuideSumCad > 0)
                QuotaHotelVModel.GuideSum = QuotaHotelBdata.GuideSum.ToString("F") + " USD, " + QuotaHotelBdata.GuideSumCad.ToString("F") + " CAD";
            else
                QuotaHotelVModel.GuideSum = QuotaHotelBdata.GuideSum.ToString("F") + " USD";
            if (QuotaHotelBdata.FreeSumCad > 0)
                QuotaHotelVModel.FreeSum = QuotaHotelBdata.FreeSum.ToString("F") + " USD, " + QuotaHotelBdata.FreeSumCad.ToString("F") + " CAD";
            else
                QuotaHotelVModel.FreeSum = QuotaHotelBdata.FreeSum.ToString("F") + " USD";
            if (QuotaHotelBdata.DriverSumCad > 0)
                QuotaHotelVModel.DriverSum = QuotaHotelBdata.DriverSum.ToString("F") + " USD, " + QuotaHotelBdata.DriverSumCad.ToString("F") + " CAD";
            else
                QuotaHotelVModel.DriverSum = QuotaHotelBdata.DriverSum.ToString("F") + " USD";
            if (QuotaHotelBdata.BreakfSumCad > 0)
                QuotaHotelVModel.BreakfSum = QuotaHotelBdata.BreakfSum.ToString("F") + " USD, " + QuotaHotelBdata.BreakfSumCad.ToString("F") + " CAD";
            else
                QuotaHotelVModel.BreakfSum = QuotaHotelBdata.BreakfSum.ToString("F") + " USD";
            QuotaHotelVModel.NightSum = QuotaHotelBdata.NightSum.ToString();
            if (QuotaHotelBdata.LgSumCad > 0)
                QuotaHotelVModel.LgSum = QuotaHotelBdata.LgSum.ToString("F") + " USD, " + QuotaHotelBdata.LgSumCad.ToString("F") + " CAD";
            else
                QuotaHotelVModel.LgSum = QuotaHotelBdata.LgSum.ToString("F") + " USD";
            if (QuotaHotelBdata.RppSumCad > 0)
                QuotaHotelVModel.RppSum = QuotaHotelBdata.RppSum.ToString("F") + " USD, " + QuotaHotelBdata.RppSumCad.ToString("F") + " CAD";
            else
                QuotaHotelVModel.RppSum = QuotaHotelBdata.RppSum.ToString("F") + " USD";
            if (QuotaHotelBdata.SsSumCad > 0)
                QuotaHotelVModel.SsSum = QuotaHotelBdata.SsSum.ToString("F") + " USD, " + QuotaHotelBdata.SsSumCad.ToString("F") + " CAD";
            else
                QuotaHotelVModel.SsSum = QuotaHotelBdata.SsSum.ToString("F") + " USD";
            DateTime? lineDates = QuotaHotelBdata.ArrivalDate;
            QuotaHotelVModel.QuotaHotelConfirmed = QuotaHotelBdata.QuotaHotelConfirmed != null ? Convert.ToBoolean(QuotaHotelBdata.QuotaHotelConfirmed) : false;
            if (QuotaHotelBdata.Rows != null)
            {
                foreach (var hotel in QuotaHotelBdata.Rows)
                {
                    QuotaHotelVModel.Rows.Add(new QuotationHotelGridRowViewModel()
                        {
                            BFreeFlag = hotel.BFreeFlag == null ? false : (bool)hotel.BFreeFlag,
                            BGuideFlag = hotel.BGuideFlag == null ? false : (bool)hotel.BGuideFlag,
                            DriverFlag = hotel.DriverFlag == null ? false : (bool)hotel.DriverFlag,
                            FreeFlag = hotel.FreeFlag == null ? false : (bool)hotel.FreeFlag,
                            GuideFlag = hotel.GuideFlag == null ? false : (bool)hotel.GuideFlag,
                            Breakfast = Convert.ToDecimal(hotel.Breakfast).ToString("F"),
                            BrfType = hotel.BrfType,
                            HotelDesc = hotel.HotelDesc,
                            HotelM = Convert.ToBoolean(hotel.HotelMFlag),
                            Luggage = Convert.ToDecimal(hotel.Luggage).ToString("F"),
                            Nights = Convert.ToDecimal(hotel.Nights).ToString(),
                            OccTax = Convert.ToDecimal(hotel.OccTax).ToString("F"),
                            Room = Convert.ToDecimal(hotel.Room).ToString("F"),
                            RoomPP = Convert.ToDecimal(hotel.RoomPP).ToString("F"),
                            RoomTax = Convert.ToDecimal(hotel.RoomTax).ToString("F"),
                            RoomTax2 = Convert.ToDecimal(hotel.RoomTax2).ToString("F"),
                            SingleSupp = Convert.ToDecimal(hotel.SingleSupp).ToString("F"),
                            tax = Convert.ToDecimal(hotel.tax).ToString("F"),
                            QuotaID = hotel.QuotaID.ToString(),
                            LineNo = Convert.ToDecimal(hotel.LineNo).ToString(),
                            LineDate = lineDates == null ? "" : (Convert.ToDateTime(lineDates)).ToString("ddd, dd/MMM/yy"),
                            CurrencyHotel = hotel.Currency,
                            VendorID = hotel.VendorID.ToString(),
                            HotelID = hotel.ItmID,
                        });
                    lineDates = lineDates == null ? lineDates : Convert.ToDateTime(lineDates).AddDays(hotel.Nights == null ? 0 : Convert.ToInt32(hotel.Nights));
                }
            }
            return QuotaHotelVModel;
        }
        private QuotationHotelGridViewModel QuotationHotelGridDatainit(QuotaHotelGridBData QuotaHotelBdata)
        {
            QuotationHotelGridViewModel QuotaHotelVModel = new QuotationHotelGridViewModel();
            QuotaHotelVModel.Rows = new List<QuotationHotelGridRowViewModel>();
            if (QuotaHotelBdata != null)
            {
                if (QuotaHotelBdata.GuideSumCad > 0)
                    QuotaHotelVModel.GuideSum = QuotaHotelBdata.GuideSum.ToString("F") + " USD, " + QuotaHotelBdata.GuideSumCad.ToString("F") + " CAD";
                else
                    QuotaHotelVModel.GuideSum = QuotaHotelBdata.GuideSum.ToString("F") + " USD";
                if (QuotaHotelBdata.FreeSumCad > 0)
                    QuotaHotelVModel.FreeSum = QuotaHotelBdata.FreeSum.ToString("F") + " USD, " + QuotaHotelBdata.FreeSumCad.ToString("F") + " CAD";
                else
                    QuotaHotelVModel.FreeSum = QuotaHotelBdata.FreeSum.ToString("F") + " USD";
                if (QuotaHotelBdata.DriverSumCad > 0)
                    QuotaHotelVModel.DriverSum = QuotaHotelBdata.DriverSum.ToString("F") + " USD, " + QuotaHotelBdata.DriverSumCad.ToString("F") + " CAD";
                else
                    QuotaHotelVModel.DriverSum = QuotaHotelBdata.DriverSum.ToString("F") + " USD";
                if (QuotaHotelBdata.BreakfSumCad > 0)
                    QuotaHotelVModel.BreakfSum = QuotaHotelBdata.BreakfSum.ToString("F") + " USD, " + QuotaHotelBdata.BreakfSumCad.ToString("F") + " CAD";
                else
                    QuotaHotelVModel.BreakfSum = QuotaHotelBdata.BreakfSum.ToString("F") + " USD";
                QuotaHotelVModel.NightSum = QuotaHotelBdata.NightSum.ToString();
                if (QuotaHotelBdata.LgSumCad > 0)
                    QuotaHotelVModel.LgSum = QuotaHotelBdata.LgSum.ToString("F") + " USD, " + QuotaHotelBdata.LgSumCad.ToString("F") + " CAD";
                else
                    QuotaHotelVModel.LgSum = QuotaHotelBdata.LgSum.ToString("F") + " USD";
                if (QuotaHotelBdata.RppSumCad > 0)
                    QuotaHotelVModel.RppSum = QuotaHotelBdata.RppSum.ToString("F") + " USD, " + QuotaHotelBdata.RppSumCad.ToString("F") + " CAD";
                else
                    QuotaHotelVModel.RppSum = QuotaHotelBdata.RppSum.ToString("F") + " USD";
                if (QuotaHotelBdata.SsSumCad > 0)
                    QuotaHotelVModel.SsSum = QuotaHotelBdata.SsSum.ToString("F") + " USD, " + QuotaHotelBdata.SsSumCad.ToString("F") + " CAD";
                else
                    QuotaHotelVModel.SsSum = QuotaHotelBdata.SsSum.ToString("F") + " USD";
                DateTime? lineDates = QuotaHotelBdata.ArrivalDate;

                QuotaHotelVModel.QuotaHotelConfirmed = QuotaHotelBdata.QuotaHotelConfirmed != null ? Convert.ToBoolean(QuotaHotelBdata.QuotaHotelConfirmed) : false;
                if (QuotaHotelBdata.Rows != null)
                {
                    foreach (var hotel in QuotaHotelBdata.Rows)
                    {
                        QuotaHotelVModel.Rows.Add(new QuotationHotelGridRowViewModel()
                        {
                            BFreeFlag = hotel.BFreeFlag == null ? false : (bool)hotel.BFreeFlag,
                            BGuideFlag = hotel.BGuideFlag == null ? false : (bool)hotel.BGuideFlag,
                            DriverFlag = hotel.DriverFlag == null ? false : (bool)hotel.DriverFlag,
                            FreeFlag = hotel.FreeFlag == null ? false : (bool)hotel.FreeFlag,
                            GuideFlag = hotel.GuideFlag == null ? false : (bool)hotel.GuideFlag,
                            Breakfast = Convert.ToDecimal(hotel.Breakfast).ToString("F"),
                            BrfType = hotel.BrfType,
                            HotelDesc = hotel.HotelDesc,
                            HotelM = Convert.ToBoolean(hotel.HotelMFlag),
                            Luggage = Convert.ToDecimal(hotel.Luggage).ToString("F"),
                            Nights = Convert.ToDecimal(hotel.Nights).ToString(),
                            OccTax = Convert.ToDecimal(hotel.OccTax).ToString("F"),
                            Room = Convert.ToDecimal(hotel.Room).ToString("F"),
                            RoomPP = Convert.ToDecimal(hotel.RoomPP).ToString("F"),
                            RoomTax = Convert.ToDecimal(hotel.RoomTax).ToString("F"),
                            RoomTax2 = Convert.ToDecimal(hotel.RoomTax2).ToString("F"),
                            SingleSupp = Convert.ToDecimal(hotel.SingleSupp).ToString("F"),
                            tax = Convert.ToDecimal(hotel.tax).ToString("F"),
                            QuotaID = hotel.QuotaID.ToString(),
                            LineNo = Convert.ToDecimal(hotel.LineNo).ToString(),
                            LineDate = lineDates == null ? "" : (Convert.ToDateTime(lineDates)).ToString("ddd, dd/MMM/yy"),
                            CurrencyHotel = hotel.Currency,
                            VendorID = hotel.VendorID.ToString(),
                            HotelID = hotel.ItmID,
                        });
                        lineDates = lineDates == null ? lineDates : Convert.ToDateTime(lineDates).AddDays(hotel.Nights == null ? 0 : Convert.ToInt32(hotel.Nights));
                    }
                }
            }
            return QuotaHotelVModel;
        }
        private QuotationLunchDinnerGridViewModel LoadQuotationLunchDinnerGridDatainit(string QuotaId)
        {
            QuotationLunchDinnerGridViewModel QuotaLunchVModel = new QuotationLunchDinnerGridViewModel();
            QuotaLunchVModel.Rows = new List<QuotationLunchDinnerGridRowViewModel>();
            QuotaManager = new QuotationManager();
            var QuotaLunchBdata = QuotaManager.LoadQuotaLunchDinnerGrid(QuotaId);
            if (QuotaLunchBdata.GuideSumCad > 0)
                QuotaLunchVModel.GuideSum = QuotaLunchBdata.GuideSum.ToString("F") + " USD, " + QuotaLunchBdata.GuideSumCad.ToString("F") + " CAD";
            else
                QuotaLunchVModel.GuideSum = QuotaLunchBdata.GuideSum.ToString("F") + " USD";
            if (QuotaLunchBdata.FreeSumCad > 0)
                QuotaLunchVModel.FreeSum = QuotaLunchBdata.FreeSum.ToString("F") + " USD, " + QuotaLunchBdata.FreeSumCad.ToString("F") + " CAD";
            else
                QuotaLunchVModel.FreeSum = QuotaLunchBdata.FreeSum.ToString("F") + " USD";
            QuotaLunchVModel.LunchSum = QuotaLunchBdata.LunchSum.ToString();
            QuotaLunchVModel.DinnerSum = QuotaLunchBdata.DinnerSum.ToString();
            QuotaLunchVModel.LunchDinnerSum = QuotaLunchBdata.LunchDinnerSum.ToString();
            if (QuotaLunchBdata.TotalSumCad > 0)
                QuotaLunchVModel.TotalSum = QuotaLunchBdata.TotalSum.ToString("F") + " USD, " + QuotaLunchBdata.TotalSumCad.ToString("F") + " CAD";
            else
                QuotaLunchVModel.TotalSum = QuotaLunchBdata.TotalSum.ToString("F") + " USD";
            DateTime? lineDates = QuotaLunchBdata.ArrivalDate;

            QuotaLunchVModel.QuotaLunchDinnerConfirmed = QuotaLunchBdata.QuotaLunchDinnerConfirmed != null ? Convert.ToBoolean(QuotaLunchBdata.QuotaLunchDinnerConfirmed) : false;
            if (QuotaLunchBdata.Rows != null)
            {
                foreach (var lunch in QuotaLunchBdata.Rows)
                {
                    lineDates = lineDates == null ? lineDates : lunch.Day > 0 ? Convert.ToDateTime(QuotaLunchBdata.ArrivalDate).AddDays((byte)lunch.Day - 1) : Convert.ToDateTime(QuotaLunchBdata.ArrivalDate).AddDays((short)lunch.LineNo - 1);

                    QuotaLunchVModel.Rows.Add(new QuotationLunchDinnerGridRowViewModel()
                    {
                        FreeFlag = lunch.FreeFlag == null ? false : (bool)lunch.FreeFlag,
                        FreeFlagD = lunch.FreeFlagD == null ? false : (bool)lunch.FreeFlagD,
                        GuideFlag = lunch.GuideFlag == null ? false : (bool)lunch.GuideFlag,
                        GuideFlagD = lunch.GuideFlagD == null ? false : (bool)lunch.GuideFlagD,
                        DescriptionLunch = lunch.Description,
                        DescriptionLunchD = lunch.DescriptionD,
                        LunchVendorID = lunch.LunchVendorID.ToString(),
                        DinnerVendorID = lunch.DinnerVendorID.ToString(),
                        LunchMFlag = Convert.ToBoolean(lunch.LunchMFlag),
                        DinnerMFlag = Convert.ToBoolean(lunch.DinnerMFlag),
                        //LineDate = lunch.LineDate.ToString(),
                        LineDName = lunch.LineDName,
                        LineNo = Convert.ToDecimal(lunch.LineNo).ToString(),
                        QuotaID = Convert.ToDecimal(lunch.QuotaID).ToString(),
                        Day = lunch.Day.ToString(),
                        CostD = Convert.ToDecimal(lunch.CostD).ToString("F"),
                        Cost = Convert.ToDecimal(lunch.Cost).ToString("F"),
                        LineDate = lineDates == null ? "" : (Convert.ToDateTime(lineDates)).ToString("ddd, dd/MMM/yy"),
                        CurrencyLunchDinner = lunch.Currency,
                        LunchID = lunch.ItmID,
                    });
                }
            }
            return QuotaLunchVModel;
        }
        private QuotationLunchDinnerGridViewModel QuotationLunchDinnerGridDatainit(QuotaLunchDinnerGridBData QuotaLunchBdata)
        {
            QuotationLunchDinnerGridViewModel QuotaLunchVModel = new QuotationLunchDinnerGridViewModel();
            QuotaLunchVModel.Rows = new List<QuotationLunchDinnerGridRowViewModel>();

            if (QuotaLunchBdata.GuideSumCad > 0)
                QuotaLunchVModel.GuideSum = QuotaLunchBdata.GuideSum.ToString("F") + " USD, " + QuotaLunchBdata.GuideSumCad.ToString("F") + " CAD";
            else
                QuotaLunchVModel.GuideSum = QuotaLunchBdata.GuideSum.ToString("F") + " USD";
            if (QuotaLunchBdata.FreeSumCad > 0)
                QuotaLunchVModel.FreeSum = QuotaLunchBdata.FreeSum.ToString("F") + " USD, " + QuotaLunchBdata.FreeSumCad.ToString("F") + " CAD";
            else
                QuotaLunchVModel.FreeSum = QuotaLunchBdata.FreeSum.ToString("F") + " USD";
            QuotaLunchVModel.LunchSum = QuotaLunchBdata.LunchSum.ToString();
            QuotaLunchVModel.DinnerSum = QuotaLunchBdata.DinnerSum.ToString();
            QuotaLunchVModel.LunchDinnerSum = QuotaLunchBdata.LunchDinnerSum.ToString();
            if (QuotaLunchBdata.TotalSumCad > 0)
                QuotaLunchVModel.TotalSum = QuotaLunchBdata.TotalSum.ToString("F") + " USD, " + QuotaLunchBdata.TotalSumCad.ToString("F") + " CAD";
            else
                QuotaLunchVModel.TotalSum = QuotaLunchBdata.TotalSum.ToString("F") + " USD";
            DateTime? lineDates = QuotaLunchBdata.ArrivalDate;

            QuotaLunchVModel.QuotaLunchDinnerConfirmed = QuotaLunchBdata.QuotaLunchDinnerConfirmed != null ? Convert.ToBoolean(QuotaLunchBdata.QuotaLunchDinnerConfirmed) : false;
            if (QuotaLunchBdata.Rows != null)
            {
                foreach (var lunch in QuotaLunchBdata.Rows)
                {
                    lineDates = lineDates == null ? lineDates : lunch.Day > 0 ? Convert.ToDateTime(QuotaLunchBdata.ArrivalDate).AddDays((byte)lunch.Day - 1) : Convert.ToDateTime(QuotaLunchBdata.ArrivalDate).AddDays((short)lunch.LineNo - 1);

                    QuotaLunchVModel.Rows.Add(new QuotationLunchDinnerGridRowViewModel()
                    {
                        FreeFlag = lunch.FreeFlag == null ? false : (bool)lunch.FreeFlag,
                        FreeFlagD = lunch.FreeFlagD == null ? false : (bool)lunch.FreeFlagD,
                        GuideFlag = lunch.GuideFlag == null ? false : (bool)lunch.GuideFlag,
                        GuideFlagD = lunch.GuideFlagD == null ? false : (bool)lunch.GuideFlagD,
                        DescriptionLunch = lunch.Description,
                        DescriptionLunchD = lunch.DescriptionD,
                        LunchVendorID = lunch.LunchVendorID.ToString(),
                        DinnerVendorID = lunch.DinnerVendorID.ToString(),
                        LunchMFlag = Convert.ToBoolean(lunch.LunchMFlag),
                        DinnerMFlag = Convert.ToBoolean(lunch.DinnerMFlag),
                        //LineDate = lunch.LineDate.ToString(),
                        LineDName = lunch.LineDName,
                        LineNo = Convert.ToDecimal(lunch.LineNo).ToString(),
                        QuotaID = Convert.ToDecimal(lunch.QuotaID).ToString(),
                        Day = lunch.Day.ToString(),
                        CostD = Convert.ToDecimal(lunch.CostD).ToString("F"),
                        Cost = Convert.ToDecimal(lunch.Cost).ToString("F"),
                        LineDate = lineDates == null ? "" : (Convert.ToDateTime(lineDates)).ToString("ddd, dd/MMM/yy"),
                        CurrencyLunchDinner = lunch.Currency,
                        LunchID = lunch.ItmID,
                    });
                }
            }
            return QuotaLunchVModel;
        }
        private QuotationEntranceGridViewModel QuotationEntranceGridDatainit(QuotaEntranceGridBData QuotaEntranceBdata)
        {
            QuotationEntranceGridViewModel QuotaEntranceVModel = new QuotationEntranceGridViewModel();
            QuotaEntranceVModel.Rows = new List<QuotationEntranceGridRowViewModel>();

            if (QuotaEntranceBdata.GuideSumCad > 0)
                QuotaEntranceVModel.GuideSum = QuotaEntranceBdata.GuideSum.ToString("F") + " USD, " + QuotaEntranceBdata.GuideSumCad.ToString("F") + " CAD";
            else
                QuotaEntranceVModel.GuideSum = QuotaEntranceBdata.GuideSum.ToString("F") + " USD";
            if (QuotaEntranceBdata.FreeSumCad > 0)
                QuotaEntranceVModel.FreeSum = QuotaEntranceBdata.FreeSum.ToString("F") + " USD, " + QuotaEntranceBdata.FreeSumCad.ToString("F") + " CAD";
            else
                QuotaEntranceVModel.FreeSum = QuotaEntranceBdata.FreeSum.ToString("F") + " USD";
            QuotaEntranceVModel.PPSum = QuotaEntranceBdata.PPSum.ToString();
            QuotaEntranceVModel.PGSum = QuotaEntranceBdata.PGSum.ToString();
            if (QuotaEntranceBdata.TotalPPCad > 0)
                QuotaEntranceVModel.TotalPPSum = QuotaEntranceBdata.TotalPP.ToString("F") + " USD, " + QuotaEntranceBdata.TotalPPCad.ToString("F") + " CAD";
            else
                QuotaEntranceVModel.TotalPPSum = QuotaEntranceBdata.TotalPP.ToString("F") + " USD";
            if (QuotaEntranceBdata.TotalPGCad > 0)
                QuotaEntranceVModel.TotalPGSum = QuotaEntranceBdata.TotalPG.ToString("F") + " USD, " + QuotaEntranceBdata.TotalPGCad.ToString("F") + " CAD";
            else
                QuotaEntranceVModel.TotalPGSum = QuotaEntranceBdata.TotalPG.ToString("F") + " USD";
            DateTime? lineDates = QuotaEntranceBdata.ArrivalDate;
            QuotaEntranceVModel.QuotaEntranceConfirmed = QuotaEntranceBdata.QuotaEntranceConfirmed != null ? Convert.ToBoolean(QuotaEntranceBdata.QuotaEntranceConfirmed) : false;
            if (QuotaEntranceBdata.Rows != null)
            {
                foreach (var entrance in QuotaEntranceBdata.Rows)
                {
                    lineDates = lineDates == null ? lineDates : entrance.Day != null && entrance.Day > 0 ? Convert.ToDateTime(QuotaEntranceBdata.ArrivalDate).AddDays(Convert.ToInt32(entrance.Day - 1)) : Convert.ToDateTime(QuotaEntranceBdata.ArrivalDate).AddDays((short)entrance.LineNo - 1);
                    QuotaEntranceVModel.Rows.Add(new QuotationEntranceGridRowViewModel()
                    {
                        VendorID = entrance.VendorID.ToString(),
                        FreeFlag = entrance.FreeFlag == null ? false : (bool)entrance.FreeFlag,
                        GuideFlag = entrance.GuideFlag == null ? false : (bool)entrance.GuideFlag,
                        CostG = Convert.ToDecimal(entrance.CostG).ToString("F"),
                        Cost = Convert.ToDecimal(entrance.Cost).ToString("F"),
                        DescriptionEntrance = entrance.Description,
                        LineNo = Convert.ToDecimal(entrance.LineNo).ToString(),
                        QuotaID = Convert.ToDecimal(entrance.QuotaID).ToString(),
                        Day = entrance.Day.ToString(),
                        LineDate = lineDates == null ? "" : (Convert.ToDateTime(lineDates)).ToString("ddd, dd/MMM/yy"),
                        CurrencyEntrance = entrance.Currency,
                        EntranceMFlag = Convert.ToBoolean(entrance.EntranceMFlag),
                        EntranceID = entrance.ItmID,
                    });
                }
            }
            return QuotaEntranceVModel;
        }

        private QuotationMiscGridViewModel QuotationMiscGridDatainit(QuotaMiscGridBData QuotaMiscBdata)
        {
            QuotationMiscGridViewModel QuotaMiscVModel = new QuotationMiscGridViewModel();
            QuotaMiscVModel.Rows = new List<QuotationMiscGridRowViewModel>();
                        
            QuotaMiscVModel.PPSum = QuotaMiscBdata.PPSum.ToString();
            QuotaMiscVModel.PGSum = QuotaMiscBdata.PGSum.ToString();
            if (QuotaMiscBdata != null)
            {
                if (QuotaMiscBdata.TotalPPCad > 0)
                    QuotaMiscVModel.TotalPPSum = QuotaMiscBdata.TotalPP.ToString("F") + " USD, " + QuotaMiscBdata.TotalPPCad.ToString("F") + " CAD";
                else
                    QuotaMiscVModel.TotalPPSum = QuotaMiscBdata.TotalPP.ToString("F") + " USD";
                if (QuotaMiscBdata.TotalPGCad > 0)
                    QuotaMiscVModel.TotalPGSum = QuotaMiscBdata.TotalPG.ToString("F") + " USD, " + QuotaMiscBdata.TotalPGCad.ToString("F") + " CAD";
                else
                    QuotaMiscVModel.TotalPGSum = QuotaMiscBdata.TotalPG.ToString("F") + " USD";
                DateTime? lineDates = QuotaMiscBdata.ArrivalDate;
                QuotaMiscVModel.QuotaMiscConfirmed = QuotaMiscBdata.QuotaMiscConfirmed != null ? Convert.ToBoolean(QuotaMiscBdata.QuotaMiscConfirmed) : false;
                if (QuotaMiscBdata.Rows != null)
                {
                    foreach (var misc in QuotaMiscBdata.Rows)
                    {
                        lineDates = lineDates == null ? lineDates : misc.Day != null && misc.Day > 0 ? Convert.ToDateTime(QuotaMiscBdata.ArrivalDate).AddDays(Convert.ToInt32(misc.Day - 1)) : Convert.ToDateTime(QuotaMiscBdata.ArrivalDate).AddDays((short)misc.LineNo - 1);
                        QuotaMiscVModel.Rows.Add(new QuotationMiscGridRowViewModel()
                        {
                            CostG = Convert.ToDecimal(misc.CostG).ToString("F"),
                            Cost = Convert.ToDecimal(misc.Cost).ToString("F"),
                            Description = misc.Description,
                            LineNo = Convert.ToDecimal(misc.LineNo).ToString(),
                            QuotaID = Convert.ToDecimal(misc.QuotaID).ToString(),
                            Day = misc.Day.ToString(),
                            LineDate = lineDates == null ? "" : (Convert.ToDateTime(lineDates)).ToString("ddd, dd/MMM/yy"),
                            CurrencyMisc = misc.Currency,
                            Plane = Convert.ToBoolean(misc.PlaneFlag),
                            MiscID = misc.ItmID,
                        });
                    }
                }
            }
            return QuotaMiscVModel;
        }

        private QuotationBusGridViewModel QuotationBusGridDatainit(QuotaBusGridBData QuotaBusBdata, bool DayUpdate)
        {
            QuotationBusGridViewModel QuotaBusVModel = new QuotationBusGridViewModel();
            QuotaBusVModel.Service = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaBusVModel.Rows = new List<QuotationBusGridRowViewModel>();
            if (QuotaBusBdata.DriverSumCad > 0)
                QuotaBusVModel.DriverSum = QuotaBusBdata.DriverSum.ToString("F") + " USD, " + QuotaBusBdata.DriverSumCad.ToString("F") + " CAD";
            else
                QuotaBusVModel.DriverSum = QuotaBusBdata.DriverSum.ToString("F") + " USD";
            if (QuotaBusBdata.TotalSumCad > 0)
                QuotaBusVModel.TotalSum = QuotaBusBdata.TotalSum.ToString("F") + " USD, " + QuotaBusBdata.TotalSumCad.ToString("F") + " CAD";
            else
                QuotaBusVModel.TotalSum = QuotaBusBdata.TotalSum.ToString("F") + " USD";
            DateTime? lineDates = QuotaBusBdata.ArrivalDate;
            short? prevDayQty = 0;
            short? prevDay = 0;
            if (QuotaBusBdata.Service != null)
            {
                foreach (var ser in QuotaBusBdata.Service)
                {
                    QuotaBusVModel.Service.Add(new System.Web.WebPages.Html.SelectListItem { Value = ser.Key.ToString(), Text = ser.Value });
                }
            }
            QuotaBusVModel.QuotaBusConfirmed = QuotaBusBdata.QuotaBusConfirmed != null ? Convert.ToBoolean(QuotaBusBdata.QuotaBusConfirmed) : false;
            if (QuotaBusBdata.Rows != null)
            {
                foreach (var bus in QuotaBusBdata.Rows)
                {
                    //if ((bus.Day < prevDay + prevDayQty) && (DayUpdate == true))
                    //{
                    //    bus.Day = Convert.ToByte(prevDay + prevDayQty);
                    //}
                    lineDates = lineDates == null ? lineDates : bus.Day != null && bus.Day > 0 ? Convert.ToDateTime(QuotaBusBdata.ArrivalDate).AddDays(Convert.ToInt32(bus.Day - 1)) : Convert.ToDateTime(QuotaBusBdata.ArrivalDate).AddDays((short)bus.LineNo - 1);
                    QuotaBusVModel.Rows.Add(new QuotationBusGridRowViewModel()
                    {
                        VendorID = bus.VendorID.ToString(),
                        Rate = Convert.ToDecimal(bus.Rate).ToString("F"),
                        Cost = Convert.ToDecimal(bus.Cost).ToString("F"),
                        DescriptionBus = bus.Description,
                        LineNo = bus.LineNo.ToString(),
                        Qty = bus.Qty.ToString(),
                        QuotaID = bus.QuotaID.ToString(),
                        Day = bus.Day.ToString(),
                        DayQty = bus.DayQty.ToString(),
                        LineDate = lineDates == null ? "" : (Convert.ToDateTime(lineDates)).ToString("ddd, dd/MMM/yy"),
                        CurrencyBus = bus.Currency,
                        BusMFlag = Convert.ToBoolean(bus.BusMFlag),
                        SelectedServiceID = bus.ServiceID.ToString(),
                        BusID = bus.ItmID,
                    });
                    prevDayQty = bus.DayQty;
                    prevDay = bus.Day;
                }
            }
            return QuotaBusVModel;
        }

        private QuotationGuideGridViewModel QuotationGuideGridDatainit(QuotaGuideGridBData QuotaGuideBdata, bool DayUpdate)
        {
            QuotationGuideGridViewModel QuotaGuideVModel = new QuotationGuideGridViewModel();
            QuotaGuideVModel.Service = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaGuideVModel.Rows = new List<QuotationGuideGridRowViewModel>();
            if (QuotaGuideBdata.RoomLgBkCad > 0)
                QuotaGuideVModel.RoomLgBk = QuotaGuideBdata.RoomLgBk.ToString("F") + " USD, " + QuotaGuideBdata.RoomLgBkCad.ToString("F") + " CAD";
            else
                QuotaGuideVModel.RoomLgBk = QuotaGuideBdata.RoomLgBk.ToString("F") + " USD";
            if (QuotaGuideBdata.LunchDinnerCad > 0)
                QuotaGuideVModel.LunchDinner = QuotaGuideBdata.LunchDinner.ToString("F") + " USD, " + QuotaGuideBdata.LunchDinnerCad.ToString("F") + " CAD";
            else
                QuotaGuideVModel.LunchDinner = QuotaGuideBdata.LunchDinner.ToString("F") + " USD";
            if (QuotaGuideBdata.EntranceCad > 0)
                QuotaGuideVModel.Entrance = QuotaGuideBdata.Entrance.ToString("F") + " USD, " + QuotaGuideBdata.EntranceCad.ToString("F") + " CAD";
            else
                QuotaGuideVModel.Entrance = QuotaGuideBdata.Entrance.ToString("F") + " USD";
            if (QuotaGuideBdata.SallaryMiscCad > 0)
                QuotaGuideVModel.SallaryMisc = QuotaGuideBdata.SallaryMisc.ToString("F") + " USD, " + QuotaGuideBdata.SallaryMiscCad.ToString("F") + " CAD";
            else
                QuotaGuideVModel.SallaryMisc = QuotaGuideBdata.SallaryMisc.ToString("F") + " USD";
            if (QuotaGuideBdata.TotalGuideCad > 0)
                QuotaGuideVModel.TotalGuide = QuotaGuideBdata.TotalGuide.ToString("F") + " USD, " + QuotaGuideBdata.TotalGuideCad.ToString("F") + " CAD";
            else
                QuotaGuideVModel.TotalGuide = QuotaGuideBdata.TotalGuide.ToString("F") + " USD";
            if (QuotaGuideBdata.TotalExpensesCad > 0)
                QuotaGuideVModel.TotalExpenses = QuotaGuideBdata.TotalExpenses.ToString("F") + " USD, " + QuotaGuideBdata.TotalExpensesCad.ToString("F") + " CAD";
            else
                QuotaGuideVModel.TotalExpenses = QuotaGuideBdata.TotalExpenses.ToString("F") + " USD";
            QuotaGuideVModel.Count = QuotaGuideBdata.Count.ToString();
            DateTime? lineDates = QuotaGuideBdata.ArrivalDate;
            short? prevDayQty = 0;
            short? prevDay = 0;
            if (QuotaGuideBdata.Service != null)
            {
                foreach (var ser in QuotaGuideBdata.Service)
                {
                    QuotaGuideVModel.Service.Add(new System.Web.WebPages.Html.SelectListItem { Value = ser.Key.ToString(), Text = ser.Value });
                }
            }
            QuotaGuideVModel.QuotaGuideConfirmed = QuotaGuideBdata.QuotaGuideConfirmed != null ? Convert.ToBoolean(QuotaGuideBdata.QuotaGuideConfirmed) : false;
            if (QuotaGuideBdata.Rows != null)
            {
                foreach (var guide in QuotaGuideBdata.Rows)
                {
                    //if ((guide.Day < prevDay + prevDayQty) && (DayUpdate == true))
                    //{
                    //    guide.Day = Convert.ToByte(prevDay + prevDayQty);
                    //}
                    lineDates = lineDates == null ? lineDates : guide.Day != null && guide.Day > 0 ? Convert.ToDateTime(QuotaGuideBdata.ArrivalDate).AddDays(Convert.ToInt32(guide.Day - 1)) : Convert.ToDateTime(QuotaGuideBdata.ArrivalDate).AddDays((short)guide.LineNo - 1);
                    QuotaGuideVModel.Rows.Add(new QuotationGuideGridRowViewModel()
                    {
                        Rate = Convert.ToDecimal(guide.Rate).ToString("F"),
                        Cost = Convert.ToDecimal(guide.Cost).ToString("F"),
                        DescriptionGuide = guide.Description,
                        LineNo = guide.LineNo.ToString(),
                        Qty = guide.Qty.ToString(),
                        QuotaID = guide.QuotaID.ToString(),
                        GuideID = guide.GuideID.ToString(),
                        Day = guide.Day.ToString(),
                        DayQty = guide.DayQty.ToString(),
                        LineDate = lineDates == null ? "" : (Convert.ToDateTime(lineDates)).ToString("ddd, dd/MMM/yy"),
                        CurrencyGuide = guide.Currency,
                        GuideMFlag = Convert.ToBoolean(guide.GuideMFlag),
                        SelectedServiceID = guide.ServiceID.ToString(),
                        QGuideID = guide.ItmID,
                    });
                    prevDayQty = guide.DayQty;
                    prevDay = guide.Day;
                }
            }
            return QuotaGuideVModel;
        }

        private QuotationEntranceGridViewModel LoadQuotationEntranceGridDatainit(string QuotaId)
        {
            QuotationEntranceGridViewModel QuotaEntranceVModel = new QuotationEntranceGridViewModel();
            QuotaEntranceVModel.Rows = new List<QuotationEntranceGridRowViewModel>();
            QuotaManager = new QuotationManager();
            var QuotaEntranceBdata = QuotaManager.LoadQuotaEntranceGrid(QuotaId);
            if (QuotaEntranceBdata.GuideSumCad > 0)
                QuotaEntranceVModel.GuideSum = QuotaEntranceBdata.GuideSum.ToString("F") + " USD, " + QuotaEntranceBdata.GuideSumCad.ToString("F") + " CAD";
            else
                QuotaEntranceVModel.GuideSum = QuotaEntranceBdata.GuideSum.ToString("F") + " USD";
            if (QuotaEntranceBdata.FreeSumCad > 0)
                QuotaEntranceVModel.FreeSum = QuotaEntranceBdata.FreeSum.ToString("F") + " USD, " + QuotaEntranceBdata.FreeSumCad.ToString("F") + " CAD";
            else
                QuotaEntranceVModel.FreeSum = QuotaEntranceBdata.FreeSum.ToString("F") + " USD";
            QuotaEntranceVModel.PPSum = QuotaEntranceBdata.PPSum.ToString();
            QuotaEntranceVModel.PGSum = QuotaEntranceBdata.PGSum.ToString();
            if (QuotaEntranceBdata.TotalPPCad > 0)
                QuotaEntranceVModel.TotalPPSum = QuotaEntranceBdata.TotalPP.ToString("F") + " USD, " + QuotaEntranceBdata.TotalPPCad.ToString("F") + " CAD";
            else
                QuotaEntranceVModel.TotalPPSum = QuotaEntranceBdata.TotalPP.ToString("F") + " USD";
            if (QuotaEntranceBdata.TotalPGCad > 0)
                QuotaEntranceVModel.TotalPGSum = QuotaEntranceBdata.TotalPG.ToString("F") + " USD, " + QuotaEntranceBdata.TotalPGCad.ToString("F") + " CAD";
            else
                QuotaEntranceVModel.TotalPGSum = QuotaEntranceBdata.TotalPG.ToString("F") + " USD";
            DateTime? lineDates = QuotaEntranceBdata.ArrivalDate;
            QuotaEntranceVModel.QuotaEntranceConfirmed = QuotaEntranceBdata.QuotaEntranceConfirmed != null ? Convert.ToBoolean(QuotaEntranceBdata.QuotaEntranceConfirmed) : false;
            if (QuotaEntranceBdata.Rows != null)
            {
                foreach (var entrance in QuotaEntranceBdata.Rows)
                {
                    lineDates = lineDates == null ? lineDates : entrance.Day != null && entrance.Day > 0 ? Convert.ToDateTime(QuotaEntranceBdata.ArrivalDate).AddDays(Convert.ToInt32(entrance.Day - 1)) : Convert.ToDateTime(QuotaEntranceBdata.ArrivalDate).AddDays((short)entrance.LineNo - 1);
                    QuotaEntranceVModel.Rows.Add(new QuotationEntranceGridRowViewModel()
                    {
                        VendorID = entrance.VendorID.ToString(),
                        FreeFlag = entrance.FreeFlag == null ? false : (bool)entrance.FreeFlag,
                        GuideFlag = entrance.GuideFlag == null ? false : (bool)entrance.GuideFlag,
                        CostG = Convert.ToDecimal(entrance.CostG).ToString("F"),
                        Cost = Convert.ToDecimal(entrance.Cost).ToString("F"),
                        DescriptionEntrance = entrance.Description,
                        LineNo = Convert.ToDecimal(entrance.LineNo).ToString(),
                        QuotaID = Convert.ToDecimal(entrance.QuotaID).ToString(),
                        Day = entrance.Day.ToString(),
                        LineDate = lineDates == null ? "" : (Convert.ToDateTime(lineDates)).ToString("ddd, dd/MMM/yy"),
                        CurrencyEntrance = entrance.Currency,
                        EntranceMFlag = Convert.ToBoolean(entrance.EntranceMFlag),
                        EntranceID = entrance.ItmID,
                    });
                }
            }
            return QuotaEntranceVModel;
        }
        private QuotationBusGridViewModel LoadQuotationBusGridDatainit(string QuotaId)
        {
            QuotationBusGridViewModel QuotaBusVModel = new QuotationBusGridViewModel();
            QuotaBusVModel.Service = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaBusVModel.Rows = new List<QuotationBusGridRowViewModel>();
            QuotaManager = new QuotationManager();
            var QuotaBusBdata = QuotaManager.LoadQuotaBusGrid(QuotaId);
            if (QuotaBusBdata.DriverSumCad > 0)
                QuotaBusVModel.DriverSum = QuotaBusBdata.DriverSum.ToString("F") + " USD, " + QuotaBusBdata.DriverSumCad.ToString("F") + " CAD";
            else
                QuotaBusVModel.DriverSum = QuotaBusBdata.DriverSum.ToString("F") + " USD";
            if (QuotaBusBdata.TotalSumCad > 0)
                QuotaBusVModel.TotalSum = QuotaBusBdata.TotalSum.ToString("F") + " USD, " + QuotaBusBdata.TotalSumCad.ToString("F") + " CAD";
            else
                QuotaBusVModel.TotalSum = QuotaBusBdata.TotalSum.ToString("F") + " USD";
            DateTime? lineDates = QuotaBusBdata.ArrivalDate;
            short? prevDayQty = 0;
            short? prevDay = 0;
            if (QuotaBusBdata.Service != null)
            {
                foreach (var ser in QuotaBusBdata.Service)
                {
                    QuotaBusVModel.Service.Add(new System.Web.WebPages.Html.SelectListItem { Value = ser.Key.ToString(), Text = ser.Value });
                }
            }
            QuotaBusVModel.QuotaBusConfirmed = QuotaBusBdata.QuotaBusConfirmed != null ? Convert.ToBoolean(QuotaBusBdata.QuotaBusConfirmed) : false;
            if (QuotaBusBdata.Rows != null)
            {
                foreach (var bus in QuotaBusBdata.Rows)
                {
                    //if (bus.Day < prevDay + prevDayQty)
                    //{
                    //    bus.Day = Convert.ToByte(prevDay + prevDayQty);
                    //}

                    lineDates = lineDates == null ? lineDates : bus.Day != null && bus.Day > 0 ? Convert.ToDateTime(QuotaBusBdata.ArrivalDate).AddDays(Convert.ToInt32(bus.Day - 1)) : Convert.ToDateTime(QuotaBusBdata.ArrivalDate).AddDays((short)bus.LineNo - 1);
                    QuotaBusVModel.Rows.Add(new QuotationBusGridRowViewModel()
                    {
                        VendorID = bus.VendorID.ToString(),
                        Rate = Convert.ToDecimal(bus.Rate).ToString("F"),
                        Cost = Convert.ToDecimal(bus.Cost).ToString("F"),
                        DescriptionBus = bus.Description,
                        LineNo = Convert.ToDecimal(bus.LineNo).ToString(),
                        Qty = bus.Qty.ToString(),
                        QuotaID = bus.QuotaID.ToString(),
                        Day = bus.Day.ToString(),
                        DayQty = bus.DayQty.ToString(),
                        LineDate = lineDates == null ? "" : (Convert.ToDateTime(lineDates)).ToString("ddd, dd/MMM/yy"),
                        CurrencyBus = bus.Currency,
                        BusMFlag = Convert.ToBoolean(bus.BusMFlag),
                        SelectedServiceID = bus.ServiceID.ToString(),
                        BusID = bus.ItmID,
                    });
                    prevDayQty = bus.DayQty;
                    prevDay = bus.Day;
                }
            }
            return QuotaBusVModel;
        }
        private QuotationGuideGridViewModel LoadQuotationGuideGridDatainit(string QuotaId)
        {
            QuotationGuideGridViewModel QuotaGuideVModel = new QuotationGuideGridViewModel();
            QuotaGuideVModel.Service = new List<System.Web.WebPages.Html.SelectListItem>();
            QuotaGuideVModel.Rows = new List<QuotationGuideGridRowViewModel>();
            QuotaManager = new QuotationManager();
            var QuotaGuideBdata = QuotaManager.LoadQuotaGuideGrid(QuotaId);
            if (QuotaGuideBdata.RoomLgBkCad > 0)
                QuotaGuideVModel.RoomLgBk = QuotaGuideBdata.RoomLgBk.ToString("F") + " USD, " + QuotaGuideBdata.RoomLgBkCad.ToString("F") + " CAD";
            else
                QuotaGuideVModel.RoomLgBk = QuotaGuideBdata.RoomLgBk.ToString("F") + " USD";
            if (QuotaGuideBdata.LunchDinnerCad > 0)
                QuotaGuideVModel.LunchDinner = QuotaGuideBdata.LunchDinner.ToString("F") + " USD, " + QuotaGuideBdata.LunchDinnerCad.ToString("F") + " CAD";
            else
                QuotaGuideVModel.LunchDinner = QuotaGuideBdata.LunchDinner.ToString("F") + " USD";
            if (QuotaGuideBdata.EntranceCad > 0)
                QuotaGuideVModel.Entrance = QuotaGuideBdata.Entrance.ToString("F") + " USD, " + QuotaGuideBdata.EntranceCad.ToString("F") + " CAD";
            else
                QuotaGuideVModel.Entrance = QuotaGuideBdata.Entrance.ToString("F") + " USD";
            if (QuotaGuideBdata.SallaryMiscCad > 0)
                QuotaGuideVModel.SallaryMisc = QuotaGuideBdata.SallaryMisc.ToString("F") + " USD, " + QuotaGuideBdata.SallaryMiscCad.ToString("F") + " CAD";
            else
                QuotaGuideVModel.SallaryMisc = QuotaGuideBdata.SallaryMisc.ToString("F") + " USD";
            if (QuotaGuideBdata.TotalGuideCad > 0)
                QuotaGuideVModel.TotalGuide = QuotaGuideBdata.TotalGuide.ToString("F") + " USD, " + QuotaGuideBdata.TotalGuideCad.ToString("F") + " CAD";
            else
                QuotaGuideVModel.TotalGuide = QuotaGuideBdata.TotalGuide.ToString("F") + " USD";
            if (QuotaGuideBdata.TotalExpensesCad > 0)
                QuotaGuideVModel.TotalExpenses = QuotaGuideBdata.TotalExpenses.ToString("F") + " USD, " + QuotaGuideBdata.TotalExpensesCad.ToString("F") + " CAD";
            else
                QuotaGuideVModel.TotalExpenses = QuotaGuideBdata.TotalExpenses.ToString("F") + " USD";
            QuotaGuideVModel.Count = QuotaGuideBdata.Count.ToString();
            DateTime? lineDates = QuotaGuideBdata.ArrivalDate;
            short? prevDayQty = 0;
            short? prevDay = 0;
            if (QuotaGuideBdata.Service != null)
            {
                foreach (var ser in QuotaGuideBdata.Service)
                {
                    QuotaGuideVModel.Service.Add(new System.Web.WebPages.Html.SelectListItem { Value = ser.Key.ToString(), Text = ser.Value });
                }
            }
            QuotaGuideVModel.QuotaGuideConfirmed = QuotaGuideBdata.QuotaGuideConfirmed != null ? Convert.ToBoolean(QuotaGuideBdata.QuotaGuideConfirmed) : false;
            if (QuotaGuideBdata.Rows != null)
            {
                foreach (var guide in QuotaGuideBdata.Rows)
                {
                    //if (guide.Day < prevDay + prevDayQty)
                    //{
                    //    guide.Day = Convert.ToByte(prevDay + prevDayQty);
                    //}
                    lineDates = lineDates == null ? lineDates : guide.Day != null && guide.Day > 0 ? Convert.ToDateTime(QuotaGuideBdata.ArrivalDate).AddDays(Convert.ToInt32(guide.Day - 1)) : Convert.ToDateTime(QuotaGuideBdata.ArrivalDate).AddDays((short)guide.LineNo - 1);
                    QuotaGuideVModel.Rows.Add(new QuotationGuideGridRowViewModel()
                    {
                        Rate = Convert.ToDecimal(guide.Rate).ToString("F"),
                        Cost = Convert.ToDecimal(guide.Cost).ToString("F"),
                        DescriptionGuide = guide.Description,
                        LineNo = guide.LineNo.ToString(),
                        Qty = guide.Qty.ToString(),
                        QuotaID = guide.QuotaID.ToString(),
                        GuideID = guide.GuideID.ToString(),
                        Day = guide.Day.ToString(),
                        DayQty = guide.DayQty.ToString(),
                        LineDate = lineDates == null ? "" : (Convert.ToDateTime(lineDates)).ToString("ddd, dd/MMM/yy"),
                        CurrencyGuide = guide.Currency,
                        GuideMFlag = Convert.ToBoolean(guide.GuideMFlag),
                        SelectedServiceID = guide.ServiceID.ToString(),
                        QGuideID = guide.ItmID,
                    });
                    prevDayQty = guide.DayQty;
                    prevDay = guide.Day;
                }
            }
            return QuotaGuideVModel;
        }
        private QuotationMiscGridViewModel LoadQuotationMiscGridDatainit(string QuotaId)
        {
            QuotationMiscGridViewModel QuotaMiscVModel = new QuotationMiscGridViewModel();
            QuotaMiscVModel.Rows = new List<QuotationMiscGridRowViewModel>();
            QuotaManager = new QuotationManager();
            var QuotaMiscBdata = QuotaManager.LoadQuotaMiscGrid(QuotaId);
            QuotaMiscVModel.PPSum = QuotaMiscBdata.PPSum.ToString();
            QuotaMiscVModel.PGSum = QuotaMiscBdata.PGSum.ToString();
            if (QuotaMiscBdata.TotalPPCad > 0)
                QuotaMiscVModel.TotalPPSum = QuotaMiscBdata.TotalPP.ToString("F") + " USD, " + QuotaMiscBdata.TotalPPCad.ToString("F") + " CAD";
            else
                QuotaMiscVModel.TotalPPSum = QuotaMiscBdata.TotalPP.ToString("F") + " USD";
            if (QuotaMiscBdata.TotalPGCad > 0)
                QuotaMiscVModel.TotalPGSum = QuotaMiscBdata.TotalPG.ToString("F") + " USD, " + QuotaMiscBdata.TotalPGCad.ToString("F") + " CAD";
            else
                QuotaMiscVModel.TotalPGSum = QuotaMiscBdata.TotalPG.ToString("F") + " USD";
            DateTime? lineDates = QuotaMiscBdata.ArrivalDate;
            QuotaMiscVModel.QuotaMiscConfirmed = QuotaMiscBdata.QuotaMiscConfirmed != null ? Convert.ToBoolean(QuotaMiscBdata.QuotaMiscConfirmed) : false;
            if (QuotaMiscBdata.Rows != null)
            {
                foreach (var misc in QuotaMiscBdata.Rows)
                {
                    lineDates = lineDates == null ? lineDates : misc.Day != null && misc.Day > 0 ? Convert.ToDateTime(QuotaMiscBdata.ArrivalDate).AddDays(Convert.ToInt32(misc.Day - 1)) : Convert.ToDateTime(QuotaMiscBdata.ArrivalDate).AddDays((short)misc.LineNo - 1);
                    QuotaMiscVModel.Rows.Add(new QuotationMiscGridRowViewModel()
                    {
                        CostG = Convert.ToDecimal(misc.CostG).ToString("F"),
                        Cost = Convert.ToDecimal(misc.Cost).ToString("F"),
                        Description = misc.Description,
                        LineNo = Convert.ToDecimal(misc.LineNo).ToString(),
                        QuotaID = Convert.ToDecimal(misc.QuotaID).ToString(),
                        Day = misc.Day.ToString(),
                        LineDate = lineDates == null ? "" : (Convert.ToDateTime(lineDates)).ToString("ddd, dd/MMM/yy"),
                        CurrencyMisc = misc.Currency,
                        Plane = Convert.ToBoolean(misc.PlaneFlag),
                        MiscID = misc.ItmID,
                    });
                }
            }
            return QuotaMiscVModel;
        }
        private QuotationCostPriceGridViewModel LoadQuotationCostPriceGridDatainit(string QuotaId, string FreeCalc)
        {
            QuotationCostPriceGridViewModel QuotaCPriceVModel = new QuotationCostPriceGridViewModel();
            QuotaCPriceVModel.Rows = new List<QuotationCostPriceGridRowViewModel>();
            QuotaManager = new QuotationManager();
            var QuotaCostBdata = QuotaManager.LoadQuotaCostPriceGrid(QuotaId, FreeCalc);
            if (QuotaCostBdata != null)
            {
                if (Convert.ToDecimal(QuotaCostBdata.SSupSumCad) > 0)
                    QuotaCPriceVModel.SSSum = Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSum)).ToString() + " USD, " + Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSumCad)).ToString() + " CAD";
                else
                    QuotaCPriceVModel.SSSum = Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSum)).ToString() + " USD";

                if (Convert.ToDecimal(QuotaCostBdata.SSupSumCadFinal) > 0)
                    QuotaCPriceVModel.SSSumFinalCad = Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSumCadFinal)).ToString() + " CAD";

                QuotaCPriceVModel.SSSumFinal = Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSumFinal)).ToString() + " USD";
                QuotaCPriceVModel.SSAdjs = QuotaCostBdata.SSupAdjs != null ? Convert.ToDecimal(QuotaCostBdata.SSupAdjs).ToString("F") : "0.00";
                QuotaCPriceVModel.SSAdjsCad = QuotaCostBdata.SSupAdjsCad != null ? Convert.ToDecimal(QuotaCostBdata.SSupAdjsCad).ToString("F") : "0.00";
                QuotaCPriceVModel.QuotaCostPriceConfirmed = QuotaCostBdata.QuotaCostPriceConfirmed != null ? Convert.ToBoolean(QuotaCostBdata.QuotaCostPriceConfirmed) : false;
                if (QuotaCostBdata.Rows != null)
                {
                    foreach (var cost in QuotaCostBdata.Rows)
                        QuotaCPriceVModel.Rows.Add(new QuotationCostPriceGridRowViewModel()
                        {
                            QuotaID = cost.QuotaID.ToString(),
                            BusPP = Convert.ToDecimal(cost.BusPP).ToString("F"),
                            EnGPP = Convert.ToDecimal(cost.EnGPP).ToString("F"),
                            EntPP = Convert.ToDecimal(cost.EntPP).ToString("F"),
                            GivenFree = Convert.ToDecimal(cost.GivenFree).ToString("F"),
                            GivenSold = Math.Round(Convert.ToDecimal(cost.GivenSold)).ToString(),
                            GuiPP = Convert.ToDecimal(cost.GuiPP).ToString("F"),
                            HtlPP = Convert.ToDecimal(cost.HtlPP).ToString("F"),
                            LDnPP = Convert.ToDecimal(cost.LDnPP).ToString("F"),
                            LineNo = cost.LineNo.ToString(),
                            MM = cost.MM == null ? false : (bool)cost.MM,
                            MscGPP = Convert.ToDecimal(cost.MscGPP).ToString("F"),
                            MscPP = Convert.ToDecimal(cost.MscPP).ToString("F"),
                            Pax = cost.Pax.ToString(),
                            PaxL = cost.PaxL.ToString(),
                            Profit = Convert.ToDecimal(cost.Profit).ToString("F"),
                            Sold = Convert.ToDecimal(cost.Sold).ToString("F"),
                            TotalCost = Convert.ToDecimal(cost.TotalCost).ToString("F"),
                            TotalFree = Convert.ToDecimal(cost.TotalFree).ToString("F"),
                            FAdjust = Convert.ToDecimal(cost.FAdjst).ToString("F"),
                            FinalPrice = Math.Round(Convert.ToDecimal(cost.FPrice)).ToString(),
                            CurrencyCostPrice = cost.Currency,
                        });
                }
            }
            return QuotaCPriceVModel;
        }
        private QuotationCostPriceGridViewModel CalcQuotationCostPriceGridDatainit(string QuotaId, QuotaCostPriceGridBData Data, string FreeCalc)
        {
            QuotationCostPriceGridViewModel QuotaCPriceVModel = new QuotationCostPriceGridViewModel();
            QuotaCPriceVModel.Rows = new List<QuotationCostPriceGridRowViewModel>();
            QuotaManager = new QuotationManager();
            var QuotaCostBdata = QuotaManager.CalcQuotaCostPriceGrid(Convert.ToInt32(QuotaId), Data, FreeCalc);
            if (QuotaCostBdata != null)
            {
                if (Convert.ToDecimal(QuotaCostBdata.SSupSumCad) > 0)
                    QuotaCPriceVModel.SSSum = Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSum)).ToString() + " USD, " + Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSumCad)).ToString() + " CAD";
                else
                    QuotaCPriceVModel.SSSum = Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSum)).ToString() + " USD";

                if (Convert.ToDecimal(QuotaCostBdata.SSupSumCadFinal) > 0)
                    QuotaCPriceVModel.SSSumFinalCad = Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSumCadFinal)).ToString() + " CAD";

                QuotaCPriceVModel.SSSumFinal = Math.Round(Convert.ToDecimal(QuotaCostBdata.SSupSumFinal)).ToString() + " USD";
                QuotaCPriceVModel.SSAdjs = QuotaCostBdata.SSupAdjs != null ? Convert.ToDecimal(QuotaCostBdata.SSupAdjs).ToString("F") : "0.00";
                QuotaCPriceVModel.SSAdjsCad = QuotaCostBdata.SSupAdjsCad != null ? Convert.ToDecimal(QuotaCostBdata.SSupAdjsCad).ToString("F") : "0.00";
                QuotaCPriceVModel.QuotaCostPriceConfirmed = QuotaCostBdata.QuotaCostPriceConfirmed != null ? Convert.ToBoolean(QuotaCostBdata.QuotaCostPriceConfirmed) : false;
                if (QuotaCostBdata.Rows != null)
                {
                    foreach (var cost in QuotaCostBdata.Rows)
                        QuotaCPriceVModel.Rows.Add(new QuotationCostPriceGridRowViewModel()
                        {
                            QuotaID = cost.QuotaID.ToString(),
                            BusPP = Convert.ToDecimal(cost.BusPP).ToString("F"),
                            EnGPP = Convert.ToDecimal(cost.EnGPP).ToString("F"),
                            EntPP = Convert.ToDecimal(cost.EntPP).ToString("F"),
                            GivenFree = Convert.ToDecimal(cost.GivenFree).ToString("F"),
                            GivenSold = Math.Round(Convert.ToDecimal(cost.GivenSold)).ToString(),
                            GuiPP = Convert.ToDecimal(cost.GuiPP).ToString("F"),
                            HtlPP = Convert.ToDecimal(cost.HtlPP).ToString("F"),
                            LDnPP = Convert.ToDecimal(cost.LDnPP).ToString("F"),
                            LineNo = cost.LineNo.ToString(),
                            MM = cost.MM == null ? false : (bool)cost.MM,
                            MscGPP = Convert.ToDecimal(cost.MscGPP).ToString("F"),
                            MscPP = Convert.ToDecimal(cost.MscPP).ToString("F"),
                            Pax = cost.Pax.ToString(),
                            PaxL = cost.PaxL.ToString(),
                            Profit = Convert.ToDecimal(cost.Profit).ToString("F"),
                            Sold = Convert.ToDecimal(cost.Sold).ToString("F"),
                            TotalCost = Convert.ToDecimal(cost.TotalCost).ToString("F"),
                            TotalFree = Convert.ToDecimal(cost.TotalFree).ToString("F"),
                            CurrencyCostPrice = cost.Currency,
                            FAdjust = Convert.ToDecimal(cost.FAdjst).ToString("F"),
                            FinalPrice = Math.Round(Convert.ToDecimal(cost.FPrice)).ToString(),
                        });
                }
            }
            return QuotaCPriceVModel;
        }
        #endregion
    }
}